Skip to content

Commit fd4b965

Browse files
authored
Rollup merge of rust-lang#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 6312352 + db7a697 commit fd4b965

File tree

5 files changed

+234
-250
lines changed

5 files changed

+234
-250
lines changed

src/etc/gdb_rust_pretty_printing.py

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,25 @@ 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+
if self.__val.get_wrapped_value()['map']['length'] > 0:
374+
root = self.__val.get_wrapped_value()['map']['root']
375+
# get at `Option` innards
376+
root = GdbValue(root).get_child_at_index(0).get_wrapped_value()
377+
# pull out the `Some` variant of the enum
378+
try:
379+
root = root['Some']
380+
except:
381+
# Do nothing, we just want to pull out Some if it exists.
382+
# If it didn't, then it seems at least on some versions of gdb
383+
# we don't actually need to do the above line, so just skip it.
384+
pass
385+
# And now the value of the Some variant
386+
root = GdbValue(root).get_child_at_index(0).get_wrapped_value()
387+
node_ptr = root['node']
388+
i = 0
389+
for child in children_of_node(node_ptr, root['height'], False):
390+
yield (str(i), child)
391+
i = i + 1
379392

380393

381394
class RustStdBTreeMapPrinter(object):
@@ -391,13 +404,26 @@ def to_string(self):
391404
("(len: %i)" % self.__val.get_wrapped_value()['length']))
392405

393406
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
407+
if self.__val.get_wrapped_value()['length'] > 0:
408+
root = self.__val.get_wrapped_value()['root']
409+
# get at `Option` innards
410+
root = GdbValue(root).get_child_at_index(0).get_wrapped_value()
411+
# pull out the `Some` variant of the enum
412+
try:
413+
root = root['Some']
414+
except:
415+
# Do nothing, we just want to pull out Some if it exists.
416+
# If it didn't, then it seems at least on some versions of gdb
417+
# we don't actually need to do the above line, so just skip it.
418+
pass
419+
# And now the value of the Some variant
420+
root = GdbValue(root).get_child_at_index(0).get_wrapped_value()
421+
node_ptr = root['node']
422+
i = 0
423+
for child in children_of_node(node_ptr, root['height'], True):
424+
yield (str(i), child[0])
425+
yield (str(i), child[1])
426+
i = i + 1
401427

402428

403429
class RustStdStringPrinter(object):

0 commit comments

Comments
 (0)