X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Flookup_table.c;h=ca7d8b5e340c0782663f8c65eef03469d08486e9;hp=b1e868281d9cca81f687f6836704409fa2cedf37;hb=f7bdd5469328cc6bced610ccabfc7f472a0b8870;hpb=90c19e287d02a962876f74e560812e75f370dbf7 diff --git a/src/lookup_table.c b/src/lookup_table.c index b1e86828..ca7d8b5e 100644 --- a/src/lookup_table.c +++ b/src/lookup_table.c @@ -212,6 +212,43 @@ free_lookup_table(struct wim_lookup_table *table) } } +static void +lookup_table_insert_raw(struct wim_lookup_table *table, + struct wim_lookup_table_entry *lte) +{ + size_t i = lte->hash_short % table->capacity; + + hlist_add_head(<e->hash_list, &table->array[i]); +} + +static void +enlarge_lookup_table(struct wim_lookup_table *table) +{ + size_t old_capacity, new_capacity; + struct hlist_head *old_array, *new_array; + struct wim_lookup_table_entry *lte; + struct hlist_node *cur, *tmp; + size_t i; + + old_capacity = table->capacity; + new_capacity = old_capacity * 2; + new_array = CALLOC(new_capacity, sizeof(struct hlist_head)); + if (new_array == NULL) + return; + old_array = table->array; + table->array = new_array; + table->capacity = new_capacity; + + for (i = 0; i < old_capacity; i++) { + hlist_for_each_entry_safe(lte, cur, tmp, &old_array[i], hash_list) { + hlist_del(<e->hash_list); + lookup_table_insert_raw(table, lte); + } + } + FREE(old_array); +} + + /* * Inserts an entry into the lookup table. * @@ -222,11 +259,9 @@ void lookup_table_insert(struct wim_lookup_table *table, struct wim_lookup_table_entry *lte) { - size_t i = lte->hash_short % table->capacity; - hlist_add_head(<e->hash_list, &table->array[i]); - - /* XXX Make the table grow when too many entries have been inserted. */ - table->num_entries++; + lookup_table_insert_raw(table, lte); + if (++table->num_entries > table->capacity) + enlarge_lookup_table(table); } static void @@ -288,7 +323,6 @@ for_lookup_table_entry(struct wim_lookup_table *table, hlist_for_each_entry_safe(lte, pos, tmp, &table->array[i], hash_list) { - wimlib_assert2(!(lte->resource_entry.flags & WIM_RESHDR_FLAG_METADATA)); ret = visitor(lte, arg); if (ret) return ret; @@ -622,7 +656,9 @@ read_wim_lookup_table(WIMStruct *wim) * resource. */ struct wim_lookup_table_entry *prev_entry = NULL; - if (back_to_back_pack) { + if (back_to_back_pack && + !list_empty(&cur_rspec->stream_list)) + { prev_entry = list_entry(cur_rspec->stream_list.prev, struct wim_lookup_table_entry, rspec_node); @@ -808,7 +844,7 @@ read_wim_lookup_table(WIMStruct *wim) goto out_free_buf; out_free_cur_entry: - FREE(cur_entry); + free_lookup_table_entry(cur_entry); out_free_lookup_table: free_lookup_table(table); out_free_buf: @@ -834,8 +870,7 @@ write_wim_lookup_table_from_stream_list(struct list_head *stream_list, struct filedes *out_fd, u16 part_number, struct wim_reshdr *out_reshdr, - int write_resource_flags, - struct wimlib_lzx_context **comp_ctx) + int write_resource_flags) { size_t table_size; struct wim_lookup_table_entry *lte; @@ -915,8 +950,7 @@ write_wim_lookup_table_from_stream_list(struct list_head *stream_list, 0, out_reshdr, NULL, - write_resource_flags, - comp_ctx); + write_resource_flags); FREE(table_buf); DEBUG("ret=%d", ret); return ret; @@ -1142,7 +1176,7 @@ wim_pathname_to_stream(WIMStruct *wim, } } - dentry = get_dentry(wim, path); + dentry = get_dentry(wim, path, WIMLIB_CASE_SENSITIVE); if (p) *p = T(':'); if (!dentry)