Skip to content

Commit ed71bf7

Browse files
committed
Use FastIndexSet in StackTable.
1 parent 41fe653 commit ed71bf7

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

‎fxprof-processed-profile/src/stack_table.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::ser::{Serialize, SerializeMap, Serializer};
22

3-
use crate::fast_hash_map::FastHashMap;
3+
use crate::fast_hash_map::FastIndexSet;
44

55
/// The stack table stores the tree of stack nodes of a thread. The shape of the tree is encoded in
66
/// the prefix column: Root stack nodes have null as their prefix, and every non-root stack has the
@@ -40,40 +40,28 @@ use crate::fast_hash_map::FastHashMap;
4040
/// would be lost if it wasn't inherited into the nsAttrAndChildArray::InsertChildAt stack before
4141
/// transforms are applied.
4242
#[derive(Debug, Clone, Default)]
43-
pub struct StackTable {
44-
stack_prefixes: Vec<Option<usize>>,
45-
stack_frames: Vec<usize>,
46-
47-
// (parent stack, frame_index) -> stack index
48-
index: FastHashMap<(Option<usize>, usize), usize>,
49-
}
43+
pub struct StackTable(FastIndexSet<(Option<usize>, usize)>);
5044

5145
impl StackTable {
5246
pub fn new() -> Self {
5347
Default::default()
5448
}
5549

5650
pub fn index_for_stack(&mut self, prefix: Option<usize>, frame: usize) -> usize {
57-
match self.index.get(&(prefix, frame)) {
58-
Some(stack) => *stack,
59-
None => {
60-
let stack = self.stack_prefixes.len();
61-
self.stack_prefixes.push(prefix);
62-
self.stack_frames.push(frame);
63-
self.index.insert((prefix, frame), stack);
64-
stack
65-
}
66-
}
51+
let (stack_index, _is_new) = self.0.insert_full((prefix, frame));
52+
stack_index
6753
}
6854
}
6955

7056
impl Serialize for StackTable {
7157
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
72-
let len = self.stack_prefixes.len();
58+
let len = self.0.len();
7359
let mut map = serializer.serialize_map(Some(3))?;
7460
map.serialize_entry("length", &len)?;
75-
map.serialize_entry("prefix", &self.stack_prefixes)?;
76-
map.serialize_entry("frame", &self.stack_frames)?;
61+
let prefix_col: Vec<_> = self.0.iter().map(|(prefix, _)| *prefix).collect();
62+
let frame_col: Vec<_> = self.0.iter().map(|(_, frame)| *frame).collect();
63+
map.serialize_entry("prefix", &prefix_col)?;
64+
map.serialize_entry("frame", &frame_col)?;
7765
map.end()
7866
}
7967
}

0 commit comments

Comments
 (0)