Skip to content

Commit 9d9e381

Browse files
authored
Rollup merge of #70111 - Mark-Simulacrum:btree-no-shared, r=cuviper
BTreeMap: remove shared root This replaces the shared root with `Option`s in the BTreeMap code, and then slightly cleans up the node manipulation code taking advantage of the removal of the shared root. I expect that further simplification is possible, but wanted to get this posted for initial review. Note that `BTreeMap::new()` continues to not allocate. Benchmarks seem within the margin of error/unaffected, as expected for an entirely predictable branch. ``` name alloc-bench-a ns/iter alloc-bench-b ns/iter diff ns/iter diff % speedup btree::map::iter_mut_20 20 21 1 5.00% x 0.95 btree::set::clone_100 1,360 1,439 79 5.81% x 0.95 btree::set::clone_100_and_into_iter 1,319 1,434 115 8.72% x 0.92 btree::set::clone_10k 143,515 150,991 7,476 5.21% x 0.95 btree::set::clone_10k_and_clear 142,792 152,916 10,124 7.09% x 0.93 btree::set::clone_10k_and_into_iter 146,019 154,561 8,542 5.85% x 0.94 ```
2 parents 67e418c + bce7f6f commit 9d9e381

File tree

6 files changed

+223
-266
lines changed

6 files changed

+223
-266
lines changed

src/etc/gdb_rust_pretty_printing.py

+21-13
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,17 @@ def to_string(self):
370370
("(len: %i)" % self.__val.get_wrapped_value()['map']['length']))
371371

372372
def children(self):
373-
root = self.__val.get_wrapped_value()['map']['root']
374-
node_ptr = root['node']
375-
i = 0
376-
for child in children_of_node(node_ptr, root['height'], False):
377-
yield (str(i), child)
378-
i = i + 1
373+
prev_idx = None
374+
innermap = GdbValue(self.__val.get_wrapped_value()['map'])
375+
if innermap.get_wrapped_value()['length'] > 0:
376+
root = GdbValue(innermap.get_wrapped_value()['root'])
377+
type_name = str(root.type.ty.name).replace('core::option::Option<', '')[:-1]
378+
root = root.get_wrapped_value().cast(gdb.lookup_type(type_name))
379+
node_ptr = root['node']
380+
i = 0
381+
for child in children_of_node(node_ptr, root['height'], False):
382+
yield (str(i), child)
383+
i = i + 1
379384

380385

381386
class RustStdBTreeMapPrinter(object):
@@ -391,13 +396,16 @@ def to_string(self):
391396
("(len: %i)" % self.__val.get_wrapped_value()['length']))
392397

393398
def children(self):
394-
root = self.__val.get_wrapped_value()['root']
395-
node_ptr = root['node']
396-
i = 0
397-
for child in children_of_node(node_ptr, root['height'], True):
398-
yield (str(i), child[0])
399-
yield (str(i), child[1])
400-
i = i + 1
399+
if self.__val.get_wrapped_value()['length'] > 0:
400+
root = GdbValue(self.__val.get_wrapped_value()['root'])
401+
type_name = str(root.type.ty.name).replace('core::option::Option<', '')[:-1]
402+
root = root.get_wrapped_value().cast(gdb.lookup_type(type_name))
403+
node_ptr = root['node']
404+
i = 0
405+
for child in children_of_node(node_ptr, root['height'], True):
406+
yield (str(i), child[0])
407+
yield (str(i), child[1])
408+
i = i + 1
401409

402410

403411
class RustStdStringPrinter(object):

0 commit comments

Comments
 (0)