Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Micro-optimize Scope access #615

Merged
merged 1 commit into from Sep 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions sentry-core/src/scope/real.rs
Expand Up @@ -10,6 +10,7 @@ use crate::Client;

#[derive(Debug)]
pub struct Stack {
top: StackLayer,
layers: Vec<StackLayer>,
}

Expand Down Expand Up @@ -77,29 +78,31 @@ pub struct StackLayer {
impl Stack {
pub fn from_client_and_scope(client: Option<Arc<Client>>, scope: Arc<Scope>) -> Stack {
Stack {
layers: vec![StackLayer { client, scope }],
top: StackLayer { client, scope },
layers: vec![],
}
}

pub fn push(&mut self) {
let layer = self.layers[self.layers.len() - 1].clone();
let layer = self.top.clone();
self.layers.push(layer);
}

pub fn pop(&mut self) {
if self.layers.len() <= 1 {
if self.layers.is_empty() {
panic!("Pop from empty stack");
}
self.layers.pop().unwrap();
self.top = self.layers.pop().unwrap();
}

#[inline(always)]
pub fn top(&self) -> &StackLayer {
&self.layers[self.layers.len() - 1]
&self.top
}

#[inline(always)]
pub fn top_mut(&mut self) -> &mut StackLayer {
let top = self.layers.len() - 1;
&mut self.layers[top]
&mut self.top
}

pub fn depth(&self) -> usize {
Expand Down