@@ -41,10 +41,11 @@ type jsonParser struct {
4141
4242// NewParser returns a new JSON parser.
4343func NewParser () Interface {
44+ p := pool .New ()
4445 return & jsonParser {
4546 stack : make ([]state , 0 , 10 ),
46- parser : parse .NewParser (nil ),
47- pool : pool . New () ,
47+ parser : parse .NewParserWithCustomAllocator (nil , p . Alloc ),
48+ pool : p ,
4849 }
4950}
5051
@@ -58,7 +59,6 @@ func (p *jsonParser) Init(buf []byte) error {
5859}
5960
6061func (p * jsonParser ) nextAtStartState (action action ) error {
61- fmt .Printf ("nextAtStartState\n " )
6262 switch action {
6363 case nextAction :
6464 parseKind , err := p .parser .Next ()
@@ -101,7 +101,6 @@ func (p *jsonParser) nextAtStartState(action action) error {
101101}
102102
103103func (p * jsonParser ) nextInLeafState (action action ) error {
104- fmt .Printf ("nextInLeafState\n " )
105104 switch action {
106105 case nextAction :
107106 // We already parsed the leaf, so there is no next element.
@@ -122,7 +121,6 @@ func (p *jsonParser) nextInLeafState(action action) error {
122121}
123122
124123func (p * jsonParser ) nextAtEOF (action action ) error {
125- fmt .Printf ("nextAtEOF\n " )
126124 switch action {
127125 case nextAction :
128126 // If Next is called too many times, just keep on return EOF
@@ -143,7 +141,6 @@ func (p *jsonParser) nextAtEOF(action action) error {
143141}
144142
145143func (p * jsonParser ) nextInObjectAtKeyState (action action ) error {
146- fmt .Printf ("nextInObjectAtKeyState\n " )
147144 // inObjectAtKeyStateKind represents that we have scanned a key
148145 switch action {
149146 case nextAction :
@@ -191,7 +188,6 @@ func (p *jsonParser) nextInObjectAtKeyState(action action) error {
191188}
192189
193190func (p * jsonParser ) nextInObjectAtValueState (action action ) error {
194- fmt .Printf ("nextInObjectAtValueState\n " )
195191 // inObjectAtValueStateKind represents that we have scanned a value and Up was called.
196192 switch action {
197193 case nextAction :
@@ -224,7 +220,6 @@ func (p *jsonParser) nextInObjectAtValueState(action action) error {
224220}
225221
226222func (p * jsonParser ) nextInArrayIndexState (action action ) error {
227- fmt .Printf ("nextInArrayIndexState\n " )
228223 // inArrayIndexState represents that we have scanned an element, if it was null, bool, number or string and the first key of an object or .
229224 switch action {
230225 case nextAction :
@@ -305,7 +300,6 @@ func (p *jsonParser) nextInArrayIndexState(action action) error {
305300}
306301
307302func (p * jsonParser ) nextInArrayAfterIndexState (action action ) error {
308- fmt .Printf ("nextInArrayAfterIndexState\n " )
309303 // This is after Up was called on an element.
310304 switch action {
311305 case nextAction :
@@ -343,7 +337,6 @@ func (p *jsonParser) eof() error {
343337}
344338
345339func (p * jsonParser ) next () error {
346- fmt .Printf ("next\n " )
347340 action := p .action
348341 // do not forget to reset action
349342 p .action = nextAction
@@ -367,22 +360,18 @@ func (p *jsonParser) next() error {
367360}
368361
369362func (p * jsonParser ) Next () error {
370- fmt .Printf ("Next\n " )
371363 return p .next ()
372364}
373365
374366func (p * jsonParser ) Down () {
375- fmt .Printf ("Down\n " )
376367 p .action = downAction
377368}
378369
379370func (p * jsonParser ) Up () {
380- fmt .Printf ("Up\n " )
381371 p .action = upAction
382372}
383373
384374func (p * jsonParser ) push () error {
385- fmt .Printf ("push\n " )
386375 // Append the current state to the stack.
387376 p .stack = append (p .stack , p .state )
388377 p .state .kind = atStartStateKind
@@ -391,7 +380,6 @@ func (p *jsonParser) push() error {
391380}
392381
393382func (p * jsonParser ) pop () error {
394- fmt .Printf ("pop\n " )
395383 if len (p .stack ) == 0 {
396384 return errPop
397385 }
0 commit comments