diff options
author | Robert Bowdidge <bowdidge@apple.com> | 2003-10-03 18:45:51 -0700 |
---|---|---|
committer | Robert Bowdidge <bowdidge@gcc.gnu.org> | 2003-10-03 18:45:51 -0700 |
commit | 674c7ef12b5dfbdc5b2ab6d7435407443ac60b28 (patch) | |
tree | b51bd0681c2d36575f098bbf59cc8982cdcff3c4 /gcc | |
parent | 2eac35601213dc106bc0b9c0e698c6d71abab2ca (diff) | |
download | gcc-674c7ef12b5dfbdc5b2ab6d7435407443ac60b28.zip gcc-674c7ef12b5dfbdc5b2ab6d7435407443ac60b28.tar.gz gcc-674c7ef12b5dfbdc5b2ab6d7435407443ac60b28.tar.bz2 |
ggc-page.c: (ggc_pch_write_object) replace fseek() with fwrite() in PCH generation...
* ggc-page.c: (ggc_pch_write_object) replace fseek() with fwrite()
in PCH generation, avoiding
too-frequent flushes when writing to NFS file system
From-SVN: r72085
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/ggc-page.c | 30 |
2 files changed, 30 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4cb41d4a..e08571e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2003-10-03 Robert Bowdidge <bowdidge@apple.com> + * ggc-page.c: (ggc_pch_write_object) replace fseek() with fwrite() in + PCH generation, avoiding too-frequent flushes when writing to NFS + file system. + 2003-10-03 Ziemowit Laski <zlaski@apple.com> * objc/objc-act.c (lookup_category): Mark as 'inline'. diff --git a/gcc/ggc-page.c b/gcc/ggc-page.c index e8b3ddb..e507de6 100644 --- a/gcc/ggc-page.c +++ b/gcc/ggc-page.c @@ -1969,6 +1969,7 @@ ggc_pch_write_object (struct ggc_pch_data *d ATTRIBUTE_UNUSED, size_t size) { unsigned order; + static const char emptyBytes[256]; if (size <= 256) order = size_lookup[size]; @@ -1982,11 +1983,30 @@ ggc_pch_write_object (struct ggc_pch_data *d ATTRIBUTE_UNUSED, if (fwrite (x, size, 1, f) != 1) fatal_error ("can't write PCH file: %m"); - /* In the current implementation, SIZE is always equal to - OBJECT_SIZE (order) and so the fseek is never executed. */ - if (size != OBJECT_SIZE (order) - && fseek (f, OBJECT_SIZE (order) - size, SEEK_CUR) != 0) - fatal_error ("can't write PCH file: %m"); + /* If SIZE is not the same as OBJECT_SIZE(order), then we need to pad the + object out to OBJECT_SIZE(order). This happens for strings. */ + + if (size != OBJECT_SIZE (order)) + { + unsigned padding = OBJECT_SIZE(order) - size; + + /* To speed small writes, we use a nulled-out array that's larger + than most padding requests as the source for our null bytes. This + permits us to do the padding with fwrite() rather than fseek(), and + limits the chance the the OS may try to flush any outstanding + writes. */ + if (padding <= sizeof(emptyBytes)) + { + if (fwrite (emptyBytes, 1, padding, f) != padding) + fatal_error ("can't write PCH file"); + } + else + { + /* Larger than our buffer? Just default to fseek. */ + if (fseek (f, padding, SEEK_CUR) != 0) + fatal_error ("can't write PCH file"); + } + } d->written[order]++; if (d->written[order] == d->d.totals[order] |