summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2015-08-28 12:56:18 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2015-08-28 12:56:18 +0900
commit0a7726252427029ee8506d33ce2d4447bd5e17c4 (patch)
tree8e71eb8a40e31bdbf128e2d7437fd870d586250d
parentd6b6a733589b79d7ae021819e11f53cf2819a1a6 (diff)
eet - improve eet file storage when encoding by aligning data
this forces data when written to be aligned to 8 bytes. this makes mapping keys directly far better as from now on you can assume all data is aligned to 8 bytes allowing you, if you want, to use eet files as caches for raw binary data you mmap directly and just use (not portable though). @feat
-rw-r--r--src/lib/eet/eet_lib.c41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/lib/eet/eet_lib.c b/src/lib/eet/eet_lib.c
index 129e93fbd5..579dc28faf 100644
--- a/src/lib/eet/eet_lib.c
+++ b/src/lib/eet/eet_lib.c
@@ -57,6 +57,10 @@ EAPI Eet_Version *eet_version = &_version;
57#define EET_FILE2_DICTIONARY_ENTRY_SIZE (sizeof(int) * \ 57#define EET_FILE2_DICTIONARY_ENTRY_SIZE (sizeof(int) * \
58 EET_FILE2_DICTIONARY_ENTRY_COUNT) 58 EET_FILE2_DICTIONARY_ENTRY_COUNT)
59 59
60// force data alignmenmt in the eet file so direct mmap can work without
61// copies and we can work with alignment
62#define ALIGN 8
63
60/* prototypes of internal calls */ 64/* prototypes of internal calls */
61static Eet_File * 65static Eet_File *
62eet_cache_find(const char *path, 66eet_cache_find(const char *path,
@@ -311,9 +315,13 @@ eet_flush2(Eet_File *ef)
311 int bytes_strings = 0; 315 int bytes_strings = 0;
312 int data_offset = 0; 316 int data_offset = 0;
313 int strings_offset = 0; 317 int strings_offset = 0;
318 int data_pad = 0;
319 int pad = 0;
320 int orig_data_offset = 0;
314 int num; 321 int num;
315 int i; 322 int i;
316 int j; 323 int j;
324 unsigned char zeros[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
317 325
318 if (eet_check_pointer(ef)) 326 if (eet_check_pointer(ef))
319 return EET_ERROR_BAD_OBJECT; 327 return EET_ERROR_BAD_OBJECT;
@@ -382,6 +390,10 @@ eet_flush2(Eet_File *ef)
382 data_offset = bytes_directory_entries + bytes_dictionary_entries + 390 data_offset = bytes_directory_entries + bytes_dictionary_entries +
383 bytes_strings; 391 bytes_strings;
384 392
393 data_pad = (((data_offset + (ALIGN - 1)) / ALIGN) * ALIGN) - data_offset;
394 data_offset += data_pad;
395 orig_data_offset = data_offset;
396
385 /* write directories entry */ 397 /* write directories entry */
386 for (i = 0; i < num; i++) 398 for (i = 0; i < num; i++)
387 { 399 {
@@ -405,6 +417,9 @@ eet_flush2(Eet_File *ef)
405 strings_offset += efn->name_size; 417 strings_offset += efn->name_size;
406 data_offset += efn->size; 418 data_offset += efn->size;
407 419
420 pad = (((data_offset + (ALIGN - 1)) / ALIGN) * ALIGN) - data_offset;
421 data_offset += pad;
422
408 if (fwrite(ibuf, sizeof(ibuf), 1, fp) != 1) 423 if (fwrite(ibuf, sizeof(ibuf), 1, fp) != 1)
409 goto write_error; 424 goto write_error;
410 } 425 }
@@ -458,13 +473,30 @@ eet_flush2(Eet_File *ef)
458 goto write_error; 473 goto write_error;
459 } 474 }
460 475
476 if (data_pad > 0)
477 {
478 if (fwrite(zeros, data_pad, 1, fp) != 1)
479 goto write_error;
480 }
481
461 /* write data */ 482 /* write data */
483 data_offset = orig_data_offset;
462 for (i = 0; i < num; i++) 484 for (i = 0; i < num; i++)
463 { 485 {
464 for (efn = ef->header->directory->nodes[i]; efn; efn = efn->next) 486 for (efn = ef->header->directory->nodes[i]; efn; efn = efn->next)
465 { 487 {
466 if (fwrite(efn->data, efn->size, 1, fp) != 1) 488 if (fwrite(efn->data, efn->size, 1, fp) != 1)
467 goto write_error; 489 goto write_error;
490
491 data_offset += efn->size;
492
493 pad = (((data_offset + (ALIGN - 1)) / ALIGN) * ALIGN) - data_offset;
494 if (pad > 0)
495 {
496 data_offset += pad;
497 if (fwrite(zeros, pad, 1, fp) != 1)
498 goto write_error;
499 }
468 } 500 }
469 } 501 }
470 502
@@ -849,8 +881,11 @@ eet_internal_read2(Eet_File *ef)
849 } 881 }
850 882
851 /* compute the possible position of a signature */ 883 /* compute the possible position of a signature */
852 if (signature_base_offset < efn->offset + efn->size) 884 if (signature_base_offset < (efn->offset + efn->size))
853 signature_base_offset = efn->offset + efn->size; 885 {
886 signature_base_offset = efn->offset +
887 (((efn->size + (ALIGN - 1)) / ALIGN) * ALIGN);
888 }
854 } 889 }
855 890
856 ef->ed = NULL; 891 ef->ed = NULL;
@@ -1968,7 +2003,7 @@ eet_read_direct(Eet_File *ef,
1968 if (!efn) goto on_error; 2003 if (!efn) goto on_error;
1969 2004
1970 /* trick to detect data in memory instead of mmaped from disk */ 2005 /* trick to detect data in memory instead of mmaped from disk */
1971 if (efn->offset > ef->data_size && !efn->data) 2006 if (((efn->offset + efn->size) > ef->data_size) && !efn->data)
1972 goto on_error; 2007 goto on_error;
1973 2008
1974 /* get size (uncompressed, if compressed at all) */ 2009 /* get size (uncompressed, if compressed at all) */