@@ -328,43 +328,40 @@ impure fn resolve_path(vec[ast.ident] path, vec[u8] data) -> resolve_result {
328
328
}
329
329
330
330
impure fn move_to_item ( & ebml. reader ebml_r, int item_id) {
331
- while ( ebml. bytes_left ( ebml_r) > 0 u) {
332
- auto outer_ebml_tag = ebml. peek ( ebml_r) ;
333
- if ( outer_ebml_tag. id == metadata. tag_items ) {
334
- ebml. move_to_first_child ( ebml_r) ;
335
-
336
- while ( ebml. bytes_left ( ebml_r) > 0 u) {
337
- auto inner_ebml_tag = ebml. peek ( ebml_r) ;
338
- if ( inner_ebml_tag. id == metadata. tag_items_data_item ) {
339
- ebml. move_to_first_child ( ebml_r) ;
331
+ ebml. move_to_sibling_with_id ( ebml_r, metadata. tag_items ) ;
332
+ ebml. move_to_child_with_id ( ebml_r, metadata. tag_items_index ) ;
333
+ ebml. move_to_child_with_id ( ebml_r, metadata. tag_items_index_table ) ;
334
+ ebml. move_to_first_child ( ebml_r) ;
340
335
341
- while ( ebml . bytes_left ( ebml_r ) > 0 u ) {
342
- auto innermost_ebml_tag = ebml . peek ( ebml_r ) ;
343
- if ( innermost_ebml_tag . id == metadata . tag_def_id ) {
344
- ebml . move_to_first_child ( ebml_r ) ;
345
- auto did_data = ebml . read_data ( ebml_r ) ;
346
- ebml. move_to_parent ( ebml_r) ;
336
+ // Move to the bucket.
337
+ auto bucket_index = metadata . hash_def_num ( item_id ) % 256 u ;
338
+ auto buf_reader = ebml_r . reader . get_buf_reader ( ) ;
339
+ buf_reader . seek ( ( bucket_index * 4 u ) as int , io . seek_cur ) ;
340
+ auto bucket_pos = ebml_r . reader . read_be_uint ( 4 u ) ;
341
+ ebml. reset_reader ( ebml_r, bucket_pos ) ;
347
342
348
- auto this_did = parse_def_id ( did_data) ;
349
- if ( this_did. _1 == item_id) {
350
- // Move to the start of this item's data.
351
- ebml. move_to_parent ( ebml_r) ;
352
- ebml. move_to_first_child ( ebml_r) ;
353
- ret;
354
- }
355
- }
356
- ebml. move_to_next_sibling ( ebml_r) ;
357
- }
358
- ebml. move_to_parent ( ebml_r) ;
359
- }
360
- ebml. move_to_next_sibling ( ebml_r) ;
343
+ // Search to find the item ID in the bucket.
344
+ check ( ebml. peek ( ebml_r) . id == metadata. tag_items_index_buckets_bucket ) ;
345
+ ebml. move_to_first_child ( ebml_r) ;
346
+ while ( ebml. bytes_left ( ebml_r) > 0 u) {
347
+ if ( ebml. peek ( ebml_r) . id ==
348
+ metadata. tag_items_index_buckets_bucket_elt ) {
349
+ ebml. move_to_first_child ( ebml_r) ;
350
+ auto pos = ebml_r. reader . read_be_uint ( 4 u) ;
351
+ auto this_item_id = ebml_r. reader . read_be_uint ( 4 u) as int ;
352
+ if ( item_id == this_item_id) {
353
+ // Found the item. Move to its data and return.
354
+ ebml. reset_reader ( ebml_r, pos) ;
355
+ check ( ebml. peek ( ebml_r) . id == metadata. tag_items_data_item ) ;
356
+ ebml. move_to_first_child ( ebml_r) ;
357
+ ret;
361
358
}
362
359
ebml. move_to_parent ( ebml_r) ;
363
360
}
364
361
ebml. move_to_next_sibling ( ebml_r) ;
365
362
}
366
363
367
- log #fmt( "move_to_item: item not found: %d " , item_id) ;
364
+ log #fmt( "item %d not found in bucket at pos %u " , item_id, bucket_pos ) ;
368
365
fail;
369
366
}
370
367
0 commit comments