forked from mirrors/gecko-dev
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
2 changed files with 19 additions and 4 deletions
|
|
@ -48,6 +48,7 @@ typedef struct MarItem_ {
|
||||||
struct MarFile_ {
|
struct MarFile_ {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
MarItem *item_table[TABLESIZE];
|
MarItem *item_table[TABLESIZE];
|
||||||
|
int item_table_is_valid;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct MarFile_ MarFile;
|
typedef struct MarFile_ MarFile;
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,7 @@ static int mar_read_index(MarFile *mar) {
|
||||||
uint32_t offset_to_index, size_of_index;
|
uint32_t offset_to_index, size_of_index;
|
||||||
|
|
||||||
/* verify MAR ID */
|
/* verify MAR ID */
|
||||||
|
fseek(mar->fp, 0, SEEK_SET);
|
||||||
if (fread(id, MAR_ID_SIZE, 1, mar->fp) != 1)
|
if (fread(id, MAR_ID_SIZE, 1, mar->fp) != 1)
|
||||||
return -1;
|
return -1;
|
||||||
if (memcmp(id, MAR_ID, MAR_ID_SIZE) != 0)
|
if (memcmp(id, MAR_ID, MAR_ID_SIZE) != 0)
|
||||||
|
|
@ -160,11 +161,8 @@ static MarFile *mar_fpopen(FILE *fp)
|
||||||
}
|
}
|
||||||
|
|
||||||
mar->fp = fp;
|
mar->fp = fp;
|
||||||
|
mar->item_table_is_valid = 0;
|
||||||
memset(mar->item_table, 0, sizeof(mar->item_table));
|
memset(mar->item_table, 0, sizeof(mar->item_table));
|
||||||
if (mar_read_index(mar)) {
|
|
||||||
mar_close(mar);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mar;
|
return mar;
|
||||||
}
|
}
|
||||||
|
|
@ -489,6 +487,14 @@ const MarItem *mar_find_item(MarFile *mar, const char *name) {
|
||||||
uint32_t hash;
|
uint32_t hash;
|
||||||
const MarItem *item;
|
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);
|
hash = mar_hash_name(name);
|
||||||
|
|
||||||
item = mar->item_table[hash];
|
item = mar->item_table[hash];
|
||||||
|
|
@ -502,6 +508,14 @@ int mar_enum_items(MarFile *mar, MarItemCallback callback, void *closure) {
|
||||||
MarItem *item;
|
MarItem *item;
|
||||||
int i;
|
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) {
|
for (i = 0; i < TABLESIZE; ++i) {
|
||||||
item = mar->item_table[i];
|
item = mar->item_table[i];
|
||||||
while (item) {
|
while (item) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue