strings, builtin: remove strings.Builder.clear(), fix array.clear() not working in the JS backend (#23992)

This commit is contained in:
XiaoPangxie732 2025-03-22 23:24:59 +08:00 committed by GitHub
parent 20d7d9758b
commit 15c0e6f2bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 3 additions and 12 deletions

View file

@ -317,7 +317,7 @@ pub fn (mut a array) reverse_in_place() {
pub fn (mut a array) clear() { pub fn (mut a array) clear() {
#a.val.arr.make_copy() #a.val.arr.make_copy()
#a.val.arr.arr.clear() #a.val.arr.arr.length = 0
} }
// reduce executes a given reducer function on each element of the array, // reduce executes a given reducer function on each element of the array,

View file

@ -59,11 +59,6 @@ pub fn (mut b Builder) write_runes(runes []rune) {
} }
} }
// clear clears the buffer contents
pub fn (mut b Builder) clear() {
b = []u8{cap: b.cap}
}
// write_u8 appends a single `data` byte to the accumulated buffer // write_u8 appends a single `data` byte to the accumulated buffer
@[inline] @[inline]
pub fn (mut b Builder) write_u8(data u8) { pub fn (mut b Builder) write_u8(data u8) {
@ -246,7 +241,7 @@ pub fn (mut b Builder) str() string {
b << u8(0) b << u8(0)
bcopy := unsafe { &u8(memdup_noscan(b.data, b.len)) } bcopy := unsafe { &u8(memdup_noscan(b.data, b.len)) }
s := unsafe { bcopy.vstring_with_len(b.len - 1) } s := unsafe { bcopy.vstring_with_len(b.len - 1) }
b.trim(0) b.clear()
return s return s
} }

View file

@ -22,10 +22,6 @@ pub fn (mut b Builder) write_byte(data u8) {
b << data b << data
} }
pub fn (mut b Builder) clear() {
b = []u8{cap: b.cap}
}
pub fn (mut b Builder) write_u8(data u8) { pub fn (mut b Builder) write_u8(data u8) {
b << data b << data
} }
@ -67,7 +63,7 @@ pub fn (mut b Builder) str() string {
#for (const c of b.val.arr.arr) #for (const c of b.val.arr.arr)
#s.str += String.fromCharCode(+c) #s.str += String.fromCharCode(+c)
b.trim(0) b.clear()
return s return s
} }