A few more cases to populate the hash in addpool

This commit is contained in:
Erica Fischer
2024-02-02 14:12:34 -08:00
parent 353cdf16e6
commit 4b8574aa87
4 changed files with 24 additions and 10 deletions
+2 -1
View File
@@ -1336,7 +1336,8 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
// To distinguish a null value
{
struct stringpool p;
memfile_write(r->treefile, &p, sizeof(struct stringpool));
bool in_memory;
memfile_write(r->treefile, &p, sizeof(struct stringpool), in_memory);
}
r->file_bbox[0] = r->file_bbox[1] = UINT_MAX;
+3 -1
View File
@@ -49,10 +49,11 @@ int memfile_close(struct memfile *file) {
return 0;
}
int memfile_write(struct memfile *file, void *s, long long len) {
int memfile_write(struct memfile *file, void *s, long long len, bool &in_memory) {
// If it is full, append to the file.
// If it is not full yet, append to the string in memory.
in_memory = false;
if (file->fp != NULL) {
if (fwrite(s, sizeof(char), len, file->fp) != (size_t) len) {
return 0;
@@ -61,6 +62,7 @@ int memfile_write(struct memfile *file, void *s, long long len) {
} else {
file->map.append(std::string((char *) s, len));
file->off += len;
in_memory = true;
}
return len;
+1 -1
View File
@@ -15,7 +15,7 @@ struct memfile {
struct memfile *memfile_open(int fd);
int memfile_close(struct memfile *file);
int memfile_write(struct memfile *file, void *s, long long len);
int memfile_write(struct memfile *file, void *s, long long len, bool &in_memory);
void memfile_full(struct memfile *file);
#endif
+18 -7
View File
@@ -64,14 +64,20 @@ long long addpool(struct memfile *poolfile, struct memfile *treefile, const char
// the pool is full yet.
long long off = poolfile->off;
if (memfile_write(poolfile, &type, 1) < 0) {
bool in_memory = false;
if (memfile_write(poolfile, &type, 1, in_memory) < 0) {
perror("memfile write");
exit(EXIT_WRITE);
}
if (memfile_write(poolfile, (void *) s, strlen(s) + 1) < 0) {
if (memfile_write(poolfile, (void *) s, strlen(s) + 1, in_memory) < 0) {
perror("memfile write");
exit(EXIT_WRITE);
}
if (in_memory) {
dedup[hash_off] = off;
}
return off;
}
}
@@ -94,11 +100,12 @@ long long addpool(struct memfile *poolfile, struct memfile *treefile, const char
// to the newly-added strings.
long long off = poolfile->off;
if (memfile_write(poolfile, &type, 1) < 0) {
bool in_memory;
if (memfile_write(poolfile, &type, 1, in_memory) < 0) {
perror("memfile write");
exit(EXIT_WRITE);
}
if (memfile_write(poolfile, (void *) s, strlen(s) + 1) < 0) {
if (memfile_write(poolfile, (void *) s, strlen(s) + 1, in_memory) < 0) {
perror("memfile write");
exit(EXIT_WRITE);
}
@@ -114,14 +121,18 @@ long long addpool(struct memfile *poolfile, struct memfile *treefile, const char
}
long long off = poolfile->off;
if (memfile_write(poolfile, &type, 1) < 0) {
bool in_memory = false;
if (memfile_write(poolfile, &type, 1, in_memory) < 0) {
perror("memfile write");
exit(EXIT_WRITE);
}
if (memfile_write(poolfile, (void *) s, strlen(s) + 1) < 0) {
if (memfile_write(poolfile, (void *) s, strlen(s) + 1, in_memory) < 0) {
perror("memfile write");
exit(EXIT_WRITE);
}
if (in_memory) {
dedup[hash_off] = off;
}
if (off >= LONG_MAX || treefile->off >= LONG_MAX) {
// Tree or pool is bigger than 2GB
@@ -139,7 +150,7 @@ long long addpool(struct memfile *poolfile, struct memfile *treefile, const char
tsp.off = off;
long long p = treefile->off;
if (memfile_write(treefile, &tsp, sizeof(struct stringpool)) < 0) {
if (memfile_write(treefile, &tsp, sizeof(struct stringpool), in_memory) < 0) {
perror("memfile write");
exit(EXIT_WRITE);
}