> gcc/ChangeLog:
>
> * Makefile.in: Add lto-ltrans-cache.o.
> * lto-wrapper.cc: Use ltrans cache.
> * lto-ltrans-cache.cc: New file.
> * lto-ltrans-cache.h: New file.
OK.
> +
> +/* Computes checksum for given file, returns NULL_CHECKSUM if not
> + possible.
> + */
As a formating nit, there should be "possible. */"
> + FILE *f_first = fopen (first_filename, "rb");
> + if (!f_first)
> + return false;
> +
> + FILE *f_second = fopen (second_filename, "rb");
> + if (!f_second)
> + {
> + fclose (f_first);
> + return false;
> + }
> +
> + for (;;)
> + {
> + int c1, c2;
> + c1 = fgetc (f_first);
> + c2 = fgetc (f_second);
fgetc has kind of non-trivial overhead. For non-MMAP systems
(is Windows such?), I think allocating some buffer, say 64K
and doing fread/memcmp is probably better.
> +/* Reads next cache item from cachedata file.
> + Adds `dir/` prefix to filenames. */
> +static ltrans_file_cache::item*
> +read_cache_item (FILE* f, const char* dir)
> +{
> + checksum_t checksum;
> + uint32_t last_used;
> +
> + if (fread (&checksum, 1, checksum.size (), f) != checksum.size ())
> + return NULL;
> + if (fread (&last_used, sizeof (last_used), 1, f) != 1)
> + return NULL;
> +
> + std::string input (dir);
> + input.push_back ('/');
> + std::string output = input; /* Copy. */
> +
> + int c;
> + while ((c = getc (f)))
> + {
> + if (c == EOF)
> + return NULL;
> + input.push_back (c);
> + }
> + input.push_back (0);
> + while ((c = getc (f)))
> + {
> + if (c == EOF)
> + return NULL;
> + output.push_back (c);
> + }
> + output.push_back (0);
Isn't std::string always 0 terminated?
Patch is OK, but please update the fgetc based file compare.
Honza