@@ -239,26 +239,22 @@ func Tokenize(emits []*Emit, source string) []*Token {
239
239
if el == 0 {
240
240
return []* Token {{source , nil }}
241
241
}
242
- count := 0
243
242
index := 0
244
243
runes := []rune (source )
245
- tokens := make ([]* Token , el * 2 + 1 )
244
+ tokens := make ([]* Token , 0 , el * 2 + 1 )
246
245
for i := 0 ; i < el ; i ++ {
247
246
emit := emits [i ]
248
247
if index < emit .Begin {
249
- tokens [count ] = & Token {string (runes [index :emit .Begin ]), nil }
250
- count ++
248
+ tokens = append (tokens , & Token {string (runes [index :emit .Begin ]), nil })
251
249
}
252
- tokens [count ] = & Token {string (runes [emit .Begin :emit .End ]), emit }
253
- count ++
250
+ tokens = append (tokens , & Token {string (runes [emit .Begin :emit .End ]), emit })
254
251
index = emit .End
255
252
}
256
253
last := emits [el - 1 ]
257
254
if last .End < utf8 .RuneCountInString (source ) {
258
- tokens [count ] = & Token {string (runes [last .End :]), nil }
259
- count ++
255
+ tokens = append (tokens , & Token {string (runes [last .End :]), nil })
260
256
}
261
- return tokens [: count ]
257
+ return tokens
262
258
}
263
259
264
260
func Replace (emits []* Emit , source string , replacement string ) string {
@@ -306,19 +302,17 @@ func removeEmits(emits []*Emit, predicate func(a, b *Emit) bool) []*Emit {
306
302
replica := make ([]* Emit , el )
307
303
copy (replica , emits )
308
304
sortEmits (replica )
309
- index := 1
310
305
emit := replica [0 ]
311
- sorted := make ([]* Emit , el )
312
- sorted [ 0 ] = emit
306
+ sorted := make ([]* Emit , 0 , el )
307
+ sorted = append ( sorted , emit )
313
308
for i := 1 ; i < el ; i ++ {
314
309
next := replica [i ]
315
310
if ! predicate (emit , next ) {
316
- sorted [index ] = next
317
- index ++
311
+ sorted = append (sorted , next )
318
312
emit = next
319
313
}
320
314
}
321
- return sorted [: index ]
315
+ return sorted
322
316
}
323
317
324
318
func sortEmits (emits []* Emit ) {
0 commit comments