mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-28 05:10:49 +00:00
Bug 1473113 - Defer initializing the MAR index until it's needed. r=rstrong
--HG-- extra : source : 6ea6dde8422f745f10dbc004293d1c1bc96e6b8e
This commit is contained in:
parent
f99f3a68e7
commit
3eedff1868
@ -48,6 +48,7 @@ typedef struct MarItem_ {
|
||||
struct MarFile_ {
|
||||
FILE *fp;
|
||||
MarItem *item_table[TABLESIZE];
|
||||
int item_table_is_valid;
|
||||
};
|
||||
|
||||
typedef struct MarFile_ MarFile;
|
||||
|
@ -114,6 +114,7 @@ static int mar_read_index(MarFile *mar) {
|
||||
uint32_t offset_to_index, size_of_index;
|
||||
|
||||
/* verify MAR ID */
|
||||
fseek(mar->fp, 0, SEEK_SET);
|
||||
if (fread(id, MAR_ID_SIZE, 1, mar->fp) != 1)
|
||||
return -1;
|
||||
if (memcmp(id, MAR_ID, MAR_ID_SIZE) != 0)
|
||||
@ -160,11 +161,8 @@ static MarFile *mar_fpopen(FILE *fp)
|
||||
}
|
||||
|
||||
mar->fp = fp;
|
||||
mar->item_table_is_valid = 0;
|
||||
memset(mar->item_table, 0, sizeof(mar->item_table));
|
||||
if (mar_read_index(mar)) {
|
||||
mar_close(mar);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return mar;
|
||||
}
|
||||
@ -489,6 +487,14 @@ const MarItem *mar_find_item(MarFile *mar, const char *name) {
|
||||
uint32_t hash;
|
||||
const MarItem *item;
|
||||
|
||||
if (!mar->item_table_is_valid) {
|
||||
if (mar_read_index(mar)) {
|
||||
return NULL;
|
||||
} else {
|
||||
mar->item_table_is_valid = 1;
|
||||
}
|
||||
}
|
||||
|
||||
hash = mar_hash_name(name);
|
||||
|
||||
item = mar->item_table[hash];
|
||||
@ -502,6 +508,14 @@ int mar_enum_items(MarFile *mar, MarItemCallback callback, void *closure) {
|
||||
MarItem *item;
|
||||
int i;
|
||||
|
||||
if (!mar->item_table_is_valid) {
|
||||
if (mar_read_index(mar)) {
|
||||
return -1;
|
||||
} else {
|
||||
mar->item_table_is_valid = 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < TABLESIZE; ++i) {
|
||||
item = mar->item_table[i];
|
||||
while (item) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user