File tree 2 files changed +67
-2
lines changed
2 files changed +67
-2
lines changed Original file line number Diff line number Diff line change
1
+ import { bench , describe } from 'vitest'
2
+
3
+ import { createBuffer } from '../src/render'
4
+
5
+ describe ( 'createBuffer' , ( ) => {
6
+ let stringBuffer = createBuffer ( )
7
+
8
+ bench (
9
+ 'string only' ,
10
+ ( ) => {
11
+ for ( let i = 0 ; i < 10 ; i += 1 ) {
12
+ stringBuffer . push ( 'hello' )
13
+ }
14
+ } ,
15
+ {
16
+ setup ( ) {
17
+ stringBuffer = createBuffer ( )
18
+ } ,
19
+ } ,
20
+ )
21
+
22
+ let stringNestedBuffer = createBuffer ( )
23
+
24
+ bench (
25
+ 'string with nested' ,
26
+ ( ) => {
27
+ for ( let i = 0 ; i < 10 ; i += 1 ) {
28
+ if ( i % 3 === 0 ) {
29
+ stringNestedBuffer . push ( 'hello' )
30
+ } else {
31
+ const buffer = createBuffer ( )
32
+ buffer . push ( 'hello' )
33
+ stringNestedBuffer . push ( buffer . getBuffer ( ) )
34
+ }
35
+ }
36
+ } ,
37
+ {
38
+ setup ( ) {
39
+ stringNestedBuffer = createBuffer ( )
40
+ } ,
41
+ } ,
42
+ )
43
+
44
+ bench (
45
+ 'string with nested async' ,
46
+ ( ) => {
47
+ for ( let i = 0 ; i < 10 ; i += 1 ) {
48
+ if ( i % 3 === 0 ) {
49
+ const buffer = createBuffer ( )
50
+ buffer . push ( 'hello' )
51
+ stringNestedBuffer . push ( Promise . resolve ( buffer . getBuffer ( ) ) )
52
+ } else {
53
+ const buffer = createBuffer ( )
54
+ buffer . push ( 'hello' )
55
+ stringNestedBuffer . push ( buffer . getBuffer ( ) )
56
+ }
57
+ }
58
+ } ,
59
+ {
60
+ setup ( ) {
61
+ stringNestedBuffer = createBuffer ( )
62
+ } ,
63
+ } ,
64
+ )
65
+ } )
Original file line number Diff line number Diff line change @@ -73,9 +73,9 @@ export function createBuffer() {
73
73
const isStringItem = isString ( item )
74
74
if ( appendable && isStringItem ) {
75
75
buffer [ buffer . length - 1 ] += item as string
76
- } else {
77
- buffer . push ( item )
76
+ return
78
77
}
78
+ buffer . push ( item )
79
79
appendable = isStringItem
80
80
if ( isPromise ( item ) || ( isArray ( item ) && item . hasAsync ) ) {
81
81
// promise, or child buffer with async, mark as async.
You can’t perform that action at this time.
0 commit comments