mirror of
https://github.com/EmbarkStudios/rust-gpu.git
synced 2024-11-22 06:45:13 +00:00
parse_attrs: avoid unnecessary allocation.
This commit is contained in:
parent
2f4c67e8e0
commit
0253fbec15
@ -4,6 +4,7 @@ use rspirv::spirv::{
|
||||
AccessQualifier, BuiltIn, Dim, ExecutionMode, ExecutionModel, ImageFormat, StorageClass,
|
||||
};
|
||||
use rustc_ast::ast::{AttrKind, Attribute, Lit, LitIntType, LitKind, NestedMetaItem};
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
use std::collections::HashMap;
|
||||
|
||||
@ -460,12 +461,11 @@ pub enum SpirvAttribute {
|
||||
// reporting already happens even before we get here :(
|
||||
/// Returns empty if this attribute is not a spirv attribute, or if it's malformed (and an error is
|
||||
/// reported).
|
||||
pub fn parse_attrs(
|
||||
cx: &CodegenCx<'_>,
|
||||
attrs: &[Attribute],
|
||||
) -> impl Iterator<Item = SpirvAttribute> {
|
||||
let result =
|
||||
attrs.iter().flat_map(|attr| {
|
||||
pub fn parse_attrs<'a, 'tcx>(
|
||||
cx: &'a CodegenCx<'tcx>,
|
||||
attrs: &'tcx [Attribute],
|
||||
) -> impl Iterator<Item = SpirvAttribute> + Captures<'tcx> + 'a {
|
||||
attrs.iter().flat_map(move |attr| {
|
||||
let is_spirv = match attr.kind {
|
||||
AttrKind::Normal(ref item, _) => {
|
||||
// TODO: We ignore the rest of the path. Is this right?
|
||||
@ -514,9 +514,12 @@ pub fn parse_attrs(
|
||||
.attributes
|
||||
.get(&name.name)
|
||||
.map(|a| match a {
|
||||
SpirvAttribute::Entry(entry) => SpirvAttribute::Entry(
|
||||
parse_entry_attrs(cx, arg, &name, entry.execution_model),
|
||||
),
|
||||
SpirvAttribute::Entry(entry) => SpirvAttribute::Entry(parse_entry_attrs(
|
||||
cx,
|
||||
arg,
|
||||
&name,
|
||||
entry.execution_model,
|
||||
)),
|
||||
_ => a.clone(),
|
||||
})
|
||||
.or_else(|| {
|
||||
@ -527,9 +530,7 @@ pub fn parse_attrs(
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
// lifetimes are hard :(
|
||||
result.collect::<Vec<_>>().into_iter()
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_image(cx: &CodegenCx<'_>, attr: &NestedMetaItem) -> Option<SpirvAttribute> {
|
||||
|
Loading…
Reference in New Issue
Block a user