Skip to content

Commit

Permalink
std::trie: make lower_bound and upper_bound about 15% faster.
Browse files Browse the repository at this point in the history
I believe this is mainly due to code-size reduction.

Before:

    test [...]::bench_lower_bound ... bench:       818 ns/iter (+/- 100)
    test [...]::bench_upper_bound ... bench:       939 ns/iter (+/- 34)

After:

    test [...]::bench_lower_bound ... bench:       698 ns/iter (+/- 60)
    test [...]::bench_upper_bound ... bench:       817 ns/iter (+/- 20)
  • Loading branch information
huonw committed Jan 7, 2014
1 parent 3395f9d commit 7e446af
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/libstd/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,24 +198,24 @@ macro_rules! bound {
addr!(loop {
let children = unsafe {addr!(& $($mut_)* (*node).children)};
let child_id = chunk(key, idx);
match children[child_id] {
let (slice_idx, ret) = match children[child_id] {
Internal(ref $($mut_)* n) => {
node = addr!(& $($mut_)* **n as * $($mut_)* TrieNode<T>);
(child_id + 1, false)
}
External(stored, _) => {
if stored < key || ($upper && stored == key) {
it.stack.push(children.$slice_from(child_id + 1).$iter());
(if stored < key || ($upper && stored == key) {
child_id + 1
} else {
it.stack.push(children.$slice_from(child_id).$iter());
}
return it;
child_id
}, true)
}
Nothing => {
it.stack.push(children.$slice_from(child_id + 1).$iter());
return it
(child_id + 1, true)
}
}
it.stack.push(children.$slice_from(child_id + 1).$iter());
};
it.stack.push(children.$slice_from(slice_idx).$iter());
if ret { return it }
idx += 1;
})
}
Expand Down

0 comments on commit 7e446af

Please sign in to comment.