mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builtin: free all elements in a []string
with -autofree too
This commit is contained in:
parent
d4e16b6ddd
commit
00651c8deb
@ -485,6 +485,17 @@ pub fn (a &array) free() {
|
||||
C.free(a.data)
|
||||
}
|
||||
|
||||
[unsafe]
|
||||
pub fn (mut a []string) free() {
|
||||
$if prealloc {
|
||||
return
|
||||
}
|
||||
for s in a {
|
||||
unsafe { s.free() }
|
||||
}
|
||||
C.free(a.data)
|
||||
}
|
||||
|
||||
// str returns a string representation of the array of strings
|
||||
// => '["a", "b", "c"]'.
|
||||
pub fn (a []string) str() string {
|
||||
|
@ -2642,6 +2642,11 @@ fn (mut g Gen) autofree_variable(v ast.Var) {
|
||||
// eprintln(' > var name: ${v.name:-20s} | is_arg: ${v.is_arg.str():6} | var type: ${int(v.typ):8} | type_name: ${sym.name:-33s}')
|
||||
// }
|
||||
if sym.kind == .array {
|
||||
if sym.has_method('free') {
|
||||
free_method_name := g.typ(v.typ) + '_free'
|
||||
g.autofree_var_call(free_method_name, v)
|
||||
return
|
||||
}
|
||||
g.autofree_var_call('array_free', v)
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user