Skip to content

Commit

Permalink
Rollup merge of rust-lang#70111 - Mark-Simulacrum:btree-no-shared, r=…
Browse files Browse the repository at this point in the history
…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
```
  • Loading branch information
Dylan-DPC authored Mar 21, 2020
2 parents 0751e6a + bce7f6f commit 1bdc860
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 266 deletions.
34 changes: 21 additions & 13 deletions src/etc/gdb_rust_pretty_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,17 @@ def to_string(self):
("(len: %i)" % self.__val.get_wrapped_value()['map']['length']))

def children(self):
root = self.__val.get_wrapped_value()['map']['root']
node_ptr = root['node']
i = 0
for child in children_of_node(node_ptr, root['height'], False):
yield (str(i), child)
i = i + 1
prev_idx = None
innermap = GdbValue(self.__val.get_wrapped_value()['map'])
if innermap.get_wrapped_value()['length'] > 0:
root = GdbValue(innermap.get_wrapped_value()['root'])
type_name = str(root.type.ty.name).replace('core::option::Option<', '')[:-1]
root = root.get_wrapped_value().cast(gdb.lookup_type(type_name))
node_ptr = root['node']
i = 0
for child in children_of_node(node_ptr, root['height'], False):
yield (str(i), child)
i = i + 1


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

def children(self):
root = self.__val.get_wrapped_value()['root']
node_ptr = root['node']
i = 0
for child in children_of_node(node_ptr, root['height'], True):
yield (str(i), child[0])
yield (str(i), child[1])
i = i + 1
if self.__val.get_wrapped_value()['length'] > 0:
root = GdbValue(self.__val.get_wrapped_value()['root'])
type_name = str(root.type.ty.name).replace('core::option::Option<', '')[:-1]
root = root.get_wrapped_value().cast(gdb.lookup_type(type_name))
node_ptr = root['node']
i = 0
for child in children_of_node(node_ptr, root['height'], True):
yield (str(i), child[0])
yield (str(i), child[1])
i = i + 1


class RustStdStringPrinter(object):
Expand Down
Loading

0 comments on commit 1bdc860

Please sign in to comment.