Skip to content

Commit

Permalink
feat: Add take method to Arena
Browse files Browse the repository at this point in the history
Add take method to Arena to avoid unnecessary cloning.
  • Loading branch information
junjunjd committed Feb 18, 2025
1 parent 9da04c2 commit cade125
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ By @cwfitzgerald in [#7030](https://github.com/gfx-rs/wgpu/pull/7030).
- Support @must_use attribute on function declarations. By @turbocrime in [#6801](https://github.com/gfx-rs/wgpu/pull/6801).
- Support for generating the candidate intersections from AABB geometry, and confirming the hits. By @kvark in [#7047](https://github.com/gfx-rs/wgpu/pull/7047).
- Make naga::back::spv::Function::to_words write the OpFunctionEnd instruction in itself, instead of making another call after it. By @junjunjd in [#7156](https://github.com/gfx-rs/wgpu/pull/7156).
- Add a take method to Arena to avoid cloning. By @junjunjd in []().
### Changes
Expand Down
4 changes: 4 additions & 0 deletions naga/src/arena/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ impl<T> Arena<T> {
}
}

pub fn take(&mut self) -> Self {
std::mem::take(self)
}

/// Extracts the inner vector.
#[allow(clippy::missing_const_for_fn)] // ignore due to requirement of #![feature(const_precise_live_drops)]
pub fn into_inner(self) -> Vec<T> {
Expand Down
4 changes: 2 additions & 2 deletions naga/src/front/wgsl/lower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,10 +1040,10 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {

pub fn lower(
&mut self,
tu: &'temp ast::TranslationUnit<'source>,
tu: &'temp mut ast::TranslationUnit<'source>,
) -> Result<crate::Module, Error<'source>> {
let mut module = crate::Module {
diagnostic_filters: tu.diagnostic_filters.clone(),
diagnostic_filters: tu.diagnostic_filters.take(),
diagnostic_filter_leaf: tu.diagnostic_filter_leaf,
..Default::default()
};
Expand Down
4 changes: 2 additions & 2 deletions naga/src/front/wgsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ impl Frontend {
}

fn inner<'a>(&mut self, source: &'a str) -> Result<crate::Module, Error<'a>> {
let tu = self.parser.parse(source)?;
let mut tu = self.parser.parse(source)?;
let index = index::Index::generate(&tu)?;
let module = Lowerer::new(&index).lower(&tu)?;
let module = Lowerer::new(&index).lower(&mut tu)?;

Ok(module)
}
Expand Down

0 comments on commit cade125

Please sign in to comment.