From 8dc4b1d9a3d1064cef0e7cbe5460976295a78c57 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Fri, 11 Mar 2022 11:07:00 +0200 Subject: [PATCH] builtin: use malloc_noscan more (for map metas and in []byte.hex()) --- vlib/builtin/array.v | 2 +- vlib/builtin/builtin.c.v | 2 +- vlib/builtin/map.v | 2 +- vlib/builtin/rune.v | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index 3b8bc040ca..74f942cfc0 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -791,7 +791,7 @@ pub fn (a []string) str() string { // hex returns a string with the hexadecimal representation // of the byte elements of the array. pub fn (b []byte) hex() string { - mut hex := unsafe { malloc(b.len * 2 + 1) } + mut hex := unsafe { malloc_noscan(b.len * 2 + 1) } mut dst_i := 0 for i in b { n0 := i >> 4 diff --git a/vlib/builtin/builtin.c.v b/vlib/builtin/builtin.c.v index 87e93bf88e..7047b3f0c7 100644 --- a/vlib/builtin/builtin.c.v +++ b/vlib/builtin/builtin.c.v @@ -324,7 +324,7 @@ pub fn malloc_noscan(n int) &byte { } $if trace_malloc ? { total_m += n - C.fprintf(C.stderr, c'_v_malloc %6d total %10d\n', n, total_m) + C.fprintf(C.stderr, c'malloc_noscan %6d total %10d\n', n, total_m) // print_backtrace() } mut res := &byte(0) diff --git a/vlib/builtin/map.v b/vlib/builtin/map.v index 266e389065..51f0af3b2b 100644 --- a/vlib/builtin/map.v +++ b/vlib/builtin/map.v @@ -662,7 +662,7 @@ pub fn (m &map) clone() map { cached_hashbits: m.cached_hashbits shift: m.shift key_values: unsafe { m.key_values.clone() } - metas: unsafe { &u32(malloc(metasize)) } + metas: unsafe { &u32(malloc_noscan(metasize)) } extra_metas: m.extra_metas len: m.len has_string_keys: m.has_string_keys diff --git a/vlib/builtin/rune.v b/vlib/builtin/rune.v index c0b5891c64..eaa893e363 100644 --- a/vlib/builtin/rune.v +++ b/vlib/builtin/rune.v @@ -18,7 +18,7 @@ pub fn (c rune) str() string { println('len=$len') mut str := string{ len: len - str: malloc(len + 1) + str: malloc_noscan(len + 1) } for i in 0..len { str.str[i] = byte(int(c)>>8 * (3 - i) & 0xff)