Skip to content

Commit

Permalink
Use conditional compilation to choose more efficient implementation
Browse files Browse the repository at this point in the history
when possible
  • Loading branch information
jlapeyre committed Feb 15, 2024
1 parent f2feeec commit 1e9cf6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/oq3_syntax/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ smol_str = "0.2.0"
stdx = { version = "0.0.188", package = "ra_ap_stdx"}
triomphe = { version = "0.1.8", default-features = false, features = ["std"] }
xshell = "0.2.2"
rustversion = "1.0"
# local crates
oq3_lexer.workspace = true
oq3_parser.workspace = true
Expand Down
14 changes: 14 additions & 0 deletions crates/oq3_syntax/src/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@ pub struct AstPtr<N: AstNode> {
}

impl<N: AstNode> Clone for AstPtr<N> {
#[rustversion::before(1.74)]
fn clone(&self) -> AstPtr<N> {
AstPtr {
raw: self.raw.clone(),
_ty: PhantomData,
}
}
#[rustversion::since(1.74)]
fn clone(&self) -> AstPtr<N> {
AstPtr {
raw: self.raw,
_ty: PhantomData,
}
}
}

impl<N: AstNode> Eq for AstPtr<N> {}
Expand Down Expand Up @@ -67,6 +75,12 @@ impl<N: AstNode> AstPtr<N> {
N::cast(syntax_node).unwrap()
}

#[rustversion::since(1.74)]
pub fn syntax_node_ptr(&self) -> SyntaxNodePtr {
self.raw
}

#[rustversion::before(1.74)]
pub fn syntax_node_ptr(&self) -> SyntaxNodePtr {
self.raw.clone()
}
Expand Down

0 comments on commit 1e9cf6e

Please sign in to comment.