From c2fe4ffa8502f026191aea80545e34947c5fb871 Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Sat, 6 Jun 2020 12:51:36 +1000 Subject: [PATCH] table: remove fn to set idx & add new derive fn --- vlib/v/checker/checker.v | 3 +-- vlib/v/gen/fn.v | 3 +-- vlib/v/table/atypes.v | 12 ++++++------ 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 5a103078a8..44b94c923d 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1743,8 +1743,7 @@ fn (mut c Checker) stmts(stmts []ast.Stmt) { pub fn (c &Checker) unwrap_generic(typ table.Type) table.Type { if typ.idx() == table.t_type_idx { // return c.cur_generic_type - // its more efficient to set the id rather than to copy flags/nr_muls - return typ.set_idx(c.cur_generic_type) + return c.cur_generic_type.derive(typ) } return typ } diff --git a/vlib/v/gen/fn.v b/vlib/v/gen/fn.v index 2a4780e11c..1d92891be7 100644 --- a/vlib/v/gen/fn.v +++ b/vlib/v/gen/fn.v @@ -331,8 +331,7 @@ fn (mut g Gen) call_expr(node ast.CallExpr) { pub fn (g &Gen) unwrap_generic(typ table.Type) table.Type { if typ.idx() == table.t_type_idx { // return g.cur_generic_type - // its more efficient to set the id rather than to copy flags/nr_muls - return typ.set_idx(g.cur_generic_type) + return g.cur_generic_type.derive(typ) } return typ } diff --git a/vlib/v/table/atypes.v b/vlib/v/table/atypes.v index bbaa8c3f48..5970b044f4 100644 --- a/vlib/v/table/atypes.v +++ b/vlib/v/table/atypes.v @@ -70,12 +70,6 @@ pub fn (t Type) is_ptr() bool { return (int(t) >> 16) & 0xff > 0 } -// set idx on `t` and return it -[inline] -pub fn (t Type) set_idx(idx int) Type { - return (((int(t) >> 24) & 0xff) << 24) | (((int(t) >> 16) & 0xff) << 16) | (u16(idx) & 0xffff) -} - // set nr_muls on `t` and return it [inline] pub fn (t Type) set_nr_muls(nr_muls int) Type { @@ -129,6 +123,12 @@ pub fn (t Type) has_flag(flag TypeFlag) bool { return (((int(t) >> 24) & 0xff) >> int(flag)) & 1 == 1 } +// copy flags & nr_muls from `t_from` to `t` and return `t` +[inline] +pub fn (t Type) derive(t_from Type) Type { + return (((int(t_from) >> 24) & 0xff) << 24) | (((int(t_from) >> 16) & 0xff) << 16) | (u16(t) & 0xffff) +} + // return new type with TypeSymbol idx set to `idx` [inline] pub fn new_type(idx int) Type {