Skip to content

Commit 15c0e6f

Browse files
strings, builtin: remove strings.Builder.clear(), fix array.clear() not working in the JS backend (#23992)
1 parent 20d7d97 commit 15c0e6f

3 files changed

Lines changed: 3 additions & 12 deletions

File tree

‎vlib/builtin/js/array.js.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ pub fn (mut a array) reverse_in_place() {
317317

318318
pub fn (mut a array) clear() {
319319
#a.val.arr.make_copy()
320-
#a.val.arr.arr.clear()
320+
#a.val.arr.arr.length = 0
321321
}
322322

323323
// reduce executes a given reducer function on each element of the array,

‎vlib/strings/builder.c.v‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ pub fn (mut b Builder) write_runes(runes []rune) {
5959
}
6060
}
6161

62-
// clear clears the buffer contents
63-
pub fn (mut b Builder) clear() {
64-
b = []u8{cap: b.cap}
65-
}
66-
6762
// write_u8 appends a single `data` byte to the accumulated buffer
6863
@[inline]
6964
pub fn (mut b Builder) write_u8(data u8) {
@@ -246,7 +241,7 @@ pub fn (mut b Builder) str() string {
246241
b << u8(0)
247242
bcopy := unsafe { &u8(memdup_noscan(b.data, b.len)) }
248243
s := unsafe { bcopy.vstring_with_len(b.len - 1) }
249-
b.trim(0)
244+
b.clear()
250245
return s
251246
}
252247

‎vlib/strings/builder.js.v‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ pub fn (mut b Builder) write_byte(data u8) {
2222
b << data
2323
}
2424

25-
pub fn (mut b Builder) clear() {
26-
b = []u8{cap: b.cap}
27-
}
28-
2925
pub fn (mut b Builder) write_u8(data u8) {
3026
b << data
3127
}
@@ -67,7 +63,7 @@ pub fn (mut b Builder) str() string {
6763

6864
#for (const c of b.val.arr.arr)
6965
#s.str += String.fromCharCode(+c)
70-
b.trim(0)
66+
b.clear()
7167
return s
7268
}
7369

0 commit comments

Comments
 (0)