20
20
public class SmileGenerator
21
21
extends GeneratorBase
22
22
{
23
+ // @since 2.16
24
+ protected final static int DEFAULT_NAME_BUFFER_LENGTH = 64 ;
25
+
26
+ // @since 2.16
27
+ protected final static int DEFAULT_STRING_VALUE_BUFFER_LENGTH = 64 ;
28
+
23
29
/**
24
30
* Enumeration that defines all togglable features for Smile generators.
25
31
*/
@@ -196,12 +202,6 @@ public SharedStringNode(String value, int index, SharedStringNode next)
196
202
*/
197
203
protected int _formatFeatures ;
198
204
199
- /**
200
- * Helper object used for low-level recycling of Smile-generator
201
- * specific buffers.
202
- */
203
- protected final SmileBufferRecycler _smileBufferRecycler ;
204
-
205
205
/*
206
206
/**********************************************************************
207
207
/* Output state
@@ -288,8 +288,7 @@ public SharedStringNode(String value, int index, SharedStringNode next)
288
288
* @since 2.16
289
289
*/
290
290
public SmileGenerator (IOContext ioCtxt , int stdFeatures , int smileFeatures ,
291
- ObjectCodec codec , OutputStream out ,
292
- SmileBufferRecycler sbr )
291
+ ObjectCodec codec , OutputStream out )
293
292
{
294
293
super (stdFeatures , codec , ioCtxt , /*WriteContext*/ null );
295
294
DupDetector dups = JsonGenerator .Feature .STRICT_DUPLICATE_DETECTION .enabledIn (stdFeatures )
@@ -299,7 +298,6 @@ public SmileGenerator(IOContext ioCtxt, int stdFeatures, int smileFeatures,
299
298
_streamWriteContext = SmileWriteContext .createRootContext (dups );
300
299
_formatFeatures = smileFeatures ;
301
300
_streamWriteConstraints = ioCtxt .streamWriteConstraints ();
302
- _smileBufferRecycler = sbr ;
303
301
_out = out ;
304
302
_bufferRecyclable = true ;
305
303
_outputBuffer = ioCtxt .allocWriteEncodingBuffer ();
@@ -314,21 +312,15 @@ public SmileGenerator(IOContext ioCtxt, int stdFeatures, int smileFeatures,
314
312
_seenNames = null ;
315
313
_seenNameCount = -1 ;
316
314
} else {
317
- _seenNames = _smileBufferRecycler .allocSeenNamesWriteBuffer ();
318
- if (_seenNames == null ) {
319
- _seenNames = new SharedStringNode [SmileBufferRecycler .DEFAULT_NAME_BUFFER_LENGTH ];
320
- }
315
+ _seenNames = new SharedStringNode [DEFAULT_NAME_BUFFER_LENGTH ];
321
316
_seenNameCount = 0 ;
322
317
}
323
318
324
319
if (!Feature .CHECK_SHARED_STRING_VALUES .enabledIn (smileFeatures )) {
325
320
_seenStringValues = null ;
326
321
_seenStringValueCount = -1 ;
327
322
} else {
328
- _seenStringValues = _smileBufferRecycler .allocSeenStringValuesWriteBuffer ();
329
- if (_seenStringValues == null ) {
330
- _seenStringValues = new SharedStringNode [SmileBufferRecycler .DEFAULT_STRING_VALUE_BUFFER_LENGTH ];
331
- }
323
+ _seenStringValues = new SharedStringNode [DEFAULT_STRING_VALUE_BUFFER_LENGTH ];
332
324
_seenStringValueCount = 0 ;
333
325
}
334
326
}
@@ -338,7 +330,6 @@ public SmileGenerator(IOContext ioCtxt, int stdFeatures, int smileFeatures,
338
330
*/
339
331
public SmileGenerator (IOContext ioCtxt , int stdFeatures , int smileFeatures ,
340
332
ObjectCodec codec , OutputStream out ,
341
- SmileBufferRecycler sbr ,
342
333
byte [] outputBuffer , int offset , boolean bufferRecyclable )
343
334
{
344
335
super (stdFeatures , codec , ioCtxt , null );
@@ -349,7 +340,6 @@ public SmileGenerator(IOContext ioCtxt, int stdFeatures, int smileFeatures,
349
340
_streamWriteContext = SmileWriteContext .createRootContext (dups );
350
341
_formatFeatures = smileFeatures ;
351
342
_streamWriteConstraints = ioCtxt .streamWriteConstraints ();
352
- _smileBufferRecycler = sbr ;
353
343
_out = out ;
354
344
_bufferRecyclable = bufferRecyclable ;
355
345
_outputTail = offset ;
@@ -365,48 +355,19 @@ public SmileGenerator(IOContext ioCtxt, int stdFeatures, int smileFeatures,
365
355
_seenNames = null ;
366
356
_seenNameCount = -1 ;
367
357
} else {
368
- _seenNames = _smileBufferRecycler .allocSeenNamesWriteBuffer ();
369
- if (_seenNames == null ) {
370
- _seenNames = new SharedStringNode [SmileBufferRecycler .DEFAULT_NAME_BUFFER_LENGTH ];
371
- }
358
+ _seenNames = new SharedStringNode [DEFAULT_NAME_BUFFER_LENGTH ];
372
359
_seenNameCount = 0 ;
373
360
}
374
361
375
362
if (!Feature .CHECK_SHARED_STRING_VALUES .enabledIn (smileFeatures )) {
376
363
_seenStringValues = null ;
377
364
_seenStringValueCount = -1 ;
378
365
} else {
379
- _seenStringValues = _smileBufferRecycler .allocSeenStringValuesWriteBuffer ();
380
- if (_seenStringValues == null ) {
381
- _seenStringValues = new SharedStringNode [SmileBufferRecycler .DEFAULT_STRING_VALUE_BUFFER_LENGTH ];
382
- }
366
+ _seenStringValues = new SharedStringNode [DEFAULT_STRING_VALUE_BUFFER_LENGTH ];
383
367
_seenStringValueCount = 0 ;
384
368
}
385
369
}
386
370
387
- /**
388
- * @deprecated Since 2.16
389
- */
390
- @ Deprecated // @since 2.16
391
- public SmileGenerator (IOContext ioCtxt , int stdFeatures , int smileFeatures ,
392
- ObjectCodec codec , OutputStream out )
393
- {
394
- this (ioCtxt , stdFeatures , smileFeatures , codec , out , new SmileBufferRecycler ());
395
- }
396
-
397
- /**
398
- * @deprecated Since 2.16
399
- */
400
- @ Deprecated // @since 2.16
401
- public SmileGenerator (IOContext ioCtxt , int stdFeatures , int smileFeatures ,
402
- ObjectCodec codec , OutputStream out ,
403
- byte [] outputBuffer , int offset , boolean bufferRecyclable )
404
- {
405
- this (ioCtxt , stdFeatures , smileFeatures ,
406
- codec , out , new SmileBufferRecycler (),
407
- outputBuffer , offset , bufferRecyclable );
408
- }
409
-
410
371
/**
411
372
* Method that can be called to explicitly write Smile document header.
412
373
* Note that usually you do not need to call this for first document to output,
@@ -2629,35 +2590,6 @@ protected void _releaseBuffers()
2629
2590
_outputBuffer = null ;
2630
2591
_ioContext .releaseWriteEncodingBuffer (buf );
2631
2592
}
2632
- /* Ok: since clearing up of larger arrays is much slower,
2633
- * let's only recycle default-sized buffers...
2634
- */
2635
- {
2636
- SharedStringNode [] nameBuf = _seenNames ;
2637
- if (nameBuf != null && nameBuf .length == SmileBufferRecycler .DEFAULT_NAME_BUFFER_LENGTH ) {
2638
- _seenNames = null ;
2639
- /* 28-Jun-2011, tatu: With 1.9, caller needs to clear the buffer; and note
2640
- * that since it's a hash area, must clear all
2641
- */
2642
- if (_seenNameCount > 0 ) {
2643
- Arrays .fill (nameBuf , null );
2644
- }
2645
- _smileBufferRecycler .releaseSeenNamesWriteBuffer (nameBuf );
2646
- }
2647
- }
2648
- {
2649
- SharedStringNode [] valueBuf = _seenStringValues ;
2650
- if (valueBuf != null && valueBuf .length == SmileBufferRecycler .DEFAULT_STRING_VALUE_BUFFER_LENGTH ) {
2651
- _seenStringValues = null ;
2652
- /* 28-Jun-2011, tatu: With 1.9, caller needs to clear the buffer; and note
2653
- * that since it's a hash area, must clear all
2654
- */
2655
- if (_seenStringValueCount > 0 ) {
2656
- Arrays .fill (valueBuf , null );
2657
- }
2658
- _smileBufferRecycler .releaseSeenStringValuesWriteBuffer (valueBuf );
2659
- }
2660
- }
2661
2593
}
2662
2594
2663
2595
protected final void _flushBuffer () throws IOException
0 commit comments