File tree 2 files changed +42
-7
lines changed
2 files changed +42
-7
lines changed Original file line number Diff line number Diff line change @@ -22,13 +22,36 @@ const schema = {
22
22
}
23
23
}
24
24
25
+ const arraySchema = {
26
+ title : 'array schema' ,
27
+ type : 'array' ,
28
+ items : schema
29
+ }
30
+
25
31
const obj = {
26
32
firstName : 'Matteo' ,
27
33
lastName : 'Collina' ,
28
34
age : 32
29
35
}
30
36
37
+ const multiArray = [
38
+ obj ,
39
+ obj ,
40
+ obj ,
41
+ obj ,
42
+ obj ,
43
+ obj ,
44
+ obj ,
45
+ obj ,
46
+ obj ,
47
+ obj ,
48
+ obj ,
49
+ obj ,
50
+ obj
51
+ ]
52
+
31
53
const stringify = require ( '.' ) ( schema )
54
+ const stringifyArray = require ( '.' ) ( arraySchema )
32
55
33
56
suite . add ( 'JSON.stringify' , function ( ) {
34
57
JSON . stringify ( obj )
@@ -42,6 +65,18 @@ suite.add('fast-safe-stringify', function () {
42
65
safeStringify ( obj )
43
66
} )
44
67
68
+ suite . add ( 'JSON.stringify array' , function ( ) {
69
+ JSON . stringify ( multiArray )
70
+ } )
71
+
72
+ suite . add ( 'fast-json-stringify array' , function ( ) {
73
+ stringifyArray ( multiArray )
74
+ } )
75
+
76
+ suite . add ( 'fast-safe-stringify array' , function ( ) {
77
+ safeStringify ( multiArray )
78
+ } )
79
+
45
80
suite . on ( 'complete' , print )
46
81
47
82
suite . run ( )
Original file line number Diff line number Diff line change @@ -43,8 +43,6 @@ function build (schema) {
43
43
return ${ main }
44
44
`
45
45
46
- // console.log(code)
47
-
48
46
return ( new Function ( code ) ) ( )
49
47
}
50
48
@@ -75,17 +73,19 @@ function $asString (str) {
75
73
var result = ''
76
74
var last = 0
77
75
var l = str . length
78
- for ( var i = 0 ; i < l ; i ++ ) {
79
- if ( str [ i ] === '"' ) {
80
- result + = str . slice ( last , i ) + '\\"'
81
- last = i + 1
82
- }
76
+ var i
77
+
78
+ while ( ( i = str . indexOf ( '"' ) ) >= 0 && i < l ) {
79
+ result += str . slice ( last , i ) + '\\"'
80
+ last = i + 1
83
81
}
82
+
84
83
if ( last === 0 ) {
85
84
result = str
86
85
} else {
87
86
result += str . slice ( last )
88
87
}
88
+
89
89
return '"' + result + '"'
90
90
}
91
91
You can’t perform that action at this time.
0 commit comments