From bc98da911175bf37d8a01ff47ce3d19b1d77615f Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 7 Nov 2021 18:05:20 +0200 Subject: [PATCH] ast: speed up the frequently called methods .find_field, .find_method etc --- vlib/v/ast/types.v | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/vlib/v/ast/types.v b/vlib/v/ast/types.v index 3ff9ed618d..87434bb47a 100644 --- a/vlib/v/ast/types.v +++ b/vlib/v/ast/types.v @@ -1184,7 +1184,7 @@ pub fn (t &TypeSymbol) embed_name() string { } pub fn (t &TypeSymbol) has_method(name string) bool { - for method in t.methods { + for mut method in unsafe { t.methods } { if method.name == name { return true } @@ -1198,7 +1198,7 @@ pub fn (t &TypeSymbol) has_method_with_generic_parent(name string) bool { } pub fn (t &TypeSymbol) find_method(name string) ?Fn { - for method in t.methods { + for mut method in unsafe { t.methods } { if method.name == name { return method } @@ -1272,7 +1272,7 @@ pub fn (t &TypeSymbol) find_field(name string) ?StructField { } fn (a &Aggregate) find_field(name string) ?StructField { - for field in a.fields { + for mut field in unsafe { a.fields } { if field.name == name { return field } @@ -1281,7 +1281,7 @@ fn (a &Aggregate) find_field(name string) ?StructField { } pub fn (i &Interface) find_field(name string) ?StructField { - for field in i.fields { + for mut field in unsafe { i.fields } { if field.name == name { return field } @@ -1290,7 +1290,7 @@ pub fn (i &Interface) find_field(name string) ?StructField { } pub fn (i &Interface) find_method(name string) ?Fn { - for method in i.methods { + for mut method in unsafe { i.methods } { if method.name == name { return method } @@ -1299,7 +1299,7 @@ pub fn (i &Interface) find_method(name string) ?Fn { } pub fn (i &Interface) has_method(name string) bool { - for method in i.methods { + for mut method in unsafe { i.methods } { if method.name == name { return true } @@ -1308,7 +1308,7 @@ pub fn (i &Interface) has_method(name string) bool { } pub fn (s Struct) find_field(name string) ?StructField { - for field in s.fields { + for mut field in unsafe { s.fields } { if field.name == name { return field } @@ -1324,7 +1324,7 @@ pub fn (s Struct) get_field(name string) StructField { } pub fn (s &SumType) find_field(name string) ?StructField { - for field in s.fields { + for mut field in unsafe { s.fields } { if field.name == name { return field } @@ -1333,7 +1333,7 @@ pub fn (s &SumType) find_field(name string) ?StructField { } pub fn (i Interface) defines_method(name string) bool { - for method in i.methods { + for mut method in unsafe { i.methods } { if method.name == name { return true }