Skip to content

Commit

Permalink
refact(rivet): remove boxed attribute from some structs
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Dec 22, 2023
1 parent 3bd1c8b commit e2b4153
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
11 changes: 4 additions & 7 deletions lib/rivet/src/ast/Attributes.ri
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@ pub struct AttributeDuplicatedError < Throwable {
}
}

#[boxed]
pub struct AttributeArgument {
pub name: string;
pub expr: Expr;
pub is_named: bool;
}

#[boxed]
pub struct Attribute {
pub name: string;
pub args: []AttributeArgument;
pub pos: token.Pos;

pub func find_argument(self, name: string) -> ?AttributeArgument {
pub func find_argument(&self, name: string) -> ?AttributeArgument {
for arg in self.args {
if arg.name == name {
return arg;
Expand All @@ -36,7 +34,6 @@ pub struct Attribute {
}
}

#[boxed]
pub struct Attributes {
pub mut attributes: []Attribute;

Expand All @@ -47,7 +44,7 @@ pub struct Attributes {
self.attributes.push(attribute);
}

pub func find(self, name: string) -> ?Attribute {
pub func find(&self, name: string) -> ?Attribute {
for attribute in self.attributes {
if attribute.name == name {
return attribute;
Expand All @@ -57,12 +54,12 @@ pub struct Attributes {
}

#[inline]
pub func has(self, name: string) -> bool {
pub func has(&self, name: string) -> bool {
return self.find(name) != none;
}

#[inline]
pub func is_empty(self) -> bool {
pub func is_empty(&self) -> bool {
return self.attributes.is_empty();
}
}
1 change: 0 additions & 1 deletion lib/rivet/src/ast/mod.ri
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub enum Node {
}
}

#[boxed]
pub struct Comment {
pub mut is_doc: bool;
pub mut text: string;
Expand Down
29 changes: 11 additions & 18 deletions lib/rivet/src/utils/maps/mod.ri
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

// TODO: remove file, use Map![K, V] instead

#[boxed]
struct StringUint {
pub key: string;
pub mut value: uint;
}

#[boxed]
pub struct MapStringUint {
mut pairs: []mut StringUint;

Expand All @@ -25,7 +23,7 @@ pub struct MapStringUint {
self.pairs.push(StringUint(key, value));
}

pub func get(self, key: string) -> ?uint {
pub func get(&self, key: string) -> ?uint {
for pair in self.pairs {
if pair.key == key {
return pair.value;
Expand All @@ -44,25 +42,23 @@ pub struct MapStringUint {
}

#[inline]
pub func contains(self, key: string) -> bool {
pub func contains(&self, key: string) -> bool {
return self.get(key) != none;
}

#[inline]
pub func len(self) -> uint {
pub func len(&self) -> uint {
return self.pairs.len;
}
}


#[boxed]
struct StringArrayOfStrings {
pub key: string;
pub mut value: []string;
}

pub struct MapStringArrayOfStringsIterator {
ref: MapStringArrayOfStrings;
ref: &MapStringArrayOfStrings;
mut idx: uint;

#[inline]
Expand All @@ -77,11 +73,10 @@ pub struct MapStringArrayOfStringsIterator {
}
}

#[boxed]
pub struct MapStringArrayOfStrings {
mut pairs: []mut StringArrayOfStrings;

pub func iterator(self) -> MapStringArrayOfStringsIterator {
pub func iterator(&self) -> MapStringArrayOfStringsIterator {
return MapStringArrayOfStringsIterator(self);
}

Expand All @@ -96,7 +91,7 @@ pub struct MapStringArrayOfStrings {
self.pairs.push(StringArrayOfStrings(key, value));
}

pub func get(self, key: string) -> ?[]string {
pub func get(&self, key: string) -> ?[]string {
for pair in self.pairs {
if pair.key == key {
return pair.value;
Expand All @@ -115,23 +110,21 @@ pub struct MapStringArrayOfStrings {
}

#[inline]
pub func contains(self, key: string) -> bool {
pub func contains(&self, key: string) -> bool {
return self.get(key) != none;
}

#[inline]
pub func len(self) -> uint {
pub func len(&self) -> uint {
return self.pairs.len;
}
}

#[boxed]
struct StringBool {
pub key: string;
pub mut value: bool;
}

#[boxed]
pub struct MapStringBool {
mut pairs: []mut StringBool;

Expand All @@ -146,7 +139,7 @@ pub struct MapStringBool {
self.pairs.push(StringBool(key, value));
}

pub func get(self, key: string) -> ?bool {
pub func get(&self, key: string) -> ?bool {
for pair in self.pairs {
if pair.key == key {
return pair.value;
Expand All @@ -165,12 +158,12 @@ pub struct MapStringBool {
}

#[inline]
pub func contains(self, key: string) -> bool {
pub func contains(&self, key: string) -> bool {
return self.get(key) != none;
}

#[inline]
pub func len(self) -> uint {
pub func len(&self) -> uint {
return self.pairs.len;
}
}

0 comments on commit e2b4153

Please sign in to comment.