From a6ec6e23bc3cb358a2099c0fb10ab6c24816b598 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 8 Sep 2019 18:53:40 +0300 Subject: [PATCH] bf: minor clean up --- compiler/parser.v | 12 +++++++++--- vlib/bitfield/bitfield.v | 9 ++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/compiler/parser.v b/compiler/parser.v index 18617d20d7..b44a2134d7 100644 --- a/compiler/parser.v +++ b/compiler/parser.v @@ -1044,8 +1044,9 @@ fn (p mut Parser) statements_no_rcbr() string { fn (p mut Parser) close_scope() { // println('close_scope level=$f.scope_level var_idx=$f.var_idx') - // Move back `var_idx` (pointer to the end of the array) till we reach the previous scope level. - // This effectivly deletes (closes) current scope. + // Move back `var_idx` (pointer to the end of the array) till we reach + // the previous scope level. This effectivly deletes (closes) current + // scope. mut i := p.cur_fn.var_idx - 1 for ; i >= 0; i-- { v := p.cur_fn.local_vars[i] @@ -1055,7 +1056,12 @@ fn (p mut Parser) close_scope() { } if p.pref.building_v && v.is_alloc { if v.typ.starts_with('array_') { - p.genln('v_array_free($v.name); // close_scope free') + if false && p.returns { + prev_line := p.cgen.lines[p.cgen.lines.len-2] + p.cgen.lines[p.cgen.lines.len-2] = 'v_array_free($v.name); /*close_scope free */' + prev_line + } else { + p.genln('v_array_free($v.name); // close_scope free') + } } else if v.typ == 'string' { //p.genln('v_string_free($v.name); // close_scope free') diff --git a/vlib/bitfield/bitfield.v b/vlib/bitfield/bitfield.v index 8d756e855a..e86840ae20 100644 --- a/vlib/bitfield/bitfield.v +++ b/vlib/bitfield/bitfield.v @@ -476,10 +476,9 @@ pub fn (instance mut BitField) reverse() BitField { return output } -// resize() changes the size of the bit array to 'new_size' - -pub fn (instance mut BitField) resize(size int) { - new_bitnslots := bitnslots(size) +// resize changes the size of the bit array to 'new_size' +pub fn (instance mut BitField) resize(new_size int) { + new_bitnslots := bitnslots(new_size) old_size := instance.size old_bitnslots := bitnslots(old_size) mut field := [u32(0); new_bitnslots] @@ -487,7 +486,7 @@ pub fn (instance mut BitField) resize(size int) { field[i] = instance.field[i] } instance.field = field.clone() - instance.size = size + instance.size = new_size if size < old_size && size % SLOT_SIZE != 0 { cleartail(mut instance) }