Skip to content

Commit e954543

Browse files
committed
Replace ProcFlags and VarTypeFlags::to_vec() with iter()
1 parent 595320a commit e954543

4 files changed

Lines changed: 54 additions & 36 deletions

File tree

crates/dreammaker/src/ast.rs

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,23 @@ impl ProcFlags {
419419
self.contains(ProcFlags::FINAL)
420420
}
421421

422-
pub fn to_vec(&self) -> Vec<&'static str> {
423-
let mut v = Vec::new();
424-
if self.is_final() {
425-
v.push("final");
422+
pub fn iter(&self) -> impl Iterator<Item = &'static str> {
423+
struct ProcFlagsIter(ProcFlags);
424+
425+
impl Iterator for ProcFlagsIter {
426+
type Item = &'static str;
427+
428+
fn next(&mut self) -> Option<Self::Item> {
429+
if self.0.is_final() {
430+
self.0 &= !ProcFlags::FINAL;
431+
Some("final")
432+
} else {
433+
None
434+
}
435+
}
426436
}
427-
v
437+
438+
ProcFlagsIter(*self)
428439
}
429440
}
430441

@@ -646,27 +657,38 @@ impl VarTypeFlags {
646657
!self.intersects(VarTypeFlags::CONST | VarTypeFlags::STATIC | VarTypeFlags::PROTECTED)
647658
}
648659

649-
pub fn to_vec(&self) -> Vec<&'static str> {
650-
let mut v = Vec::new();
651-
if self.is_static() {
652-
v.push("static");
653-
}
654-
if self.is_const() {
655-
v.push("const");
656-
}
657-
if self.is_tmp() {
658-
v.push("tmp");
659-
}
660-
if self.is_final() {
661-
v.push("final");
662-
}
663-
if self.is_private() {
664-
v.push("SpacemanDMM_private");
665-
}
666-
if self.is_protected() {
667-
v.push("SpacemanDMM_protected");
660+
pub fn iter(&self) -> impl Iterator<Item = &'static str> {
661+
struct VarTypeFlagsIter(VarTypeFlags);
662+
663+
impl Iterator for VarTypeFlagsIter {
664+
type Item = &'static str;
665+
666+
fn next(&mut self) -> Option<Self::Item> {
667+
if self.0.is_static() {
668+
self.0 &= !VarTypeFlags::STATIC;
669+
Some("static")
670+
} else if self.0.is_const() {
671+
self.0 &= !VarTypeFlags::CONST;
672+
Some("const")
673+
} else if self.0.is_tmp() {
674+
self.0 &= !VarTypeFlags::TMP;
675+
Some("tmp")
676+
} else if self.0.is_final() {
677+
self.0 &= !VarTypeFlags::FINAL;
678+
Some("final")
679+
} else if self.0.is_private() {
680+
self.0 &= !VarTypeFlags::PRIVATE;
681+
Some("SpacemanDMM_private")
682+
} else if self.0.is_protected() {
683+
self.0 &= !VarTypeFlags::PROTECTED;
684+
Some("SpacemanDMM_protected")
685+
} else {
686+
None
687+
}
688+
}
668689
}
669-
v
690+
691+
VarTypeFlagsIter(*self)
670692
}
671693
}
672694

crates/dreammaker/src/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ impl<'a> ConstantFolder<'a> {
10981098
.collect();
10991099
// Only tricky bit is adding on the type if required
11001100
if let Some(declaration) = proc_ref.get_declaration() {
1101-
path_elements.push(declaration.kind.name().into());
1101+
path_elements.push(declaration.kind.into());
11021102
}
11031103
path_elements.push(proc_ref.name().to_owned().into());
11041104
Ok(Constant::Prefab(Box::new(Pop::from(Box::from(

crates/dreammaker/src/objtree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ impl<'o> NavigatePathResult<'o> {
547547
.collect();
548548
match self {
549549
NavigatePathResult::Type(_) => {},
550-
NavigatePathResult::ProcGroup(_, kind) => path.push(kind.name().into()),
550+
NavigatePathResult::ProcGroup(_, kind) => path.push(kind.into()),
551551
NavigatePathResult::ProcPath(proc, kind) => {
552552
path.push(kind.into());
553553
path.push(Ident::from_nonstatic(proc.name()));

crates/dreammaker/src/parser.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2888,22 +2888,18 @@ fn reconstruct_path(
28882888
) -> Vec<Ident> {
28892889
let mut result: Vec<Ident> = Vec::new();
28902890
for entry in node.split('/').skip(1) {
2891-
result.push(entry.to_owned().into());
2891+
result.push(Ident::from_nonstatic(entry));
28922892
}
28932893
if let Some(deets) = proc_deets {
2894-
result.push(deets.kind.name().into());
2895-
deets
2896-
.flags
2897-
.to_vec()
2898-
.into_iter()
2899-
.for_each(|elem| result.push(elem.into()));
2894+
result.push(deets.kind.into());
2895+
result.extend(deets.flags.iter().map(From::from));
29002896
}
29012897
if let Some(var) = var_type {
2902-
result.extend(var.flags.to_vec().into_iter().map(From::from));
2898+
result.extend(var.flags.iter().map(From::from));
29032899
result.extend(var.type_path.iter().cloned());
29042900
}
29052901
if !last.is_empty() {
2906-
result.push(last.to_owned().into());
2902+
result.push(Ident::from_nonstatic(last));
29072903
}
29082904
result
29092905
}

0 commit comments

Comments
 (0)