builtin: free all elements in a []string with -autofree too

This commit is contained in:
Delyan Angelov 2021-03-18 21:10:42 +02:00
parent d4e16b6ddd
commit 00651c8deb
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED
2 changed files with 16 additions and 0 deletions

View file

@ -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 {