File tree Expand file tree Collapse file tree 2 files changed +28
-9
lines changed
main/java/org/msgpack/core
test/scala/org/msgpack/core Expand file tree Collapse file tree 2 files changed +28
-9
lines changed Original file line number Diff line number Diff line change @@ -365,8 +365,19 @@ private double readDouble()
365365 public void skipValue ()
366366 throws IOException
367367 {
368- int remainingValues = 1 ;
369- while (remainingValues > 0 ) {
368+ skipValue (1 );
369+ }
370+
371+ /**
372+ * Skip next values, then move the cursor at the end of the value
373+ *
374+ * @param count number of values to skip
375+ * @throws IOException
376+ */
377+ public void skipValue (int count )
378+ throws IOException
379+ {
380+ while (count > 0 ) {
370381 byte b = readByte ();
371382 MessageFormat f = MessageFormat .valueOf (b );
372383 switch (f ) {
@@ -377,12 +388,12 @@ public void skipValue()
377388 break ;
378389 case FIXMAP : {
379390 int mapLen = b & 0x0f ;
380- remainingValues += mapLen * 2 ;
391+ count += mapLen * 2 ;
381392 break ;
382393 }
383394 case FIXARRAY : {
384395 int arrayLen = b & 0x0f ;
385- remainingValues += arrayLen ;
396+ count += arrayLen ;
386397 break ;
387398 }
388399 case FIXSTR : {
@@ -445,22 +456,22 @@ public void skipValue()
445456 skipPayload (readNextLength32 () + 1 );
446457 break ;
447458 case ARRAY16 :
448- remainingValues += readNextLength16 ();
459+ count += readNextLength16 ();
449460 break ;
450461 case ARRAY32 :
451- remainingValues += readNextLength32 ();
462+ count += readNextLength32 ();
452463 break ;
453464 case MAP16 :
454- remainingValues += readNextLength16 () * 2 ;
465+ count += readNextLength16 () * 2 ;
455466 break ;
456467 case MAP32 :
457- remainingValues += readNextLength32 () * 2 ; // TODO check int overflow
468+ count += readNextLength32 () * 2 ; // TODO check int overflow
458469 break ;
459470 case NEVER_USED :
460471 throw new MessageNeverUsedFormatException ("Encountered 0xC1 \" NEVER_USED\" byte" );
461472 }
462473
463- remainingValues --;
474+ count --;
464475 }
465476 }
466477
Original file line number Diff line number Diff line change @@ -233,6 +233,14 @@ class MessageUnpackerTest extends MessagePackSpec {
233233 }
234234 }
235235
236+ time(" bulk skip performance" , repeat = 100 ) {
237+ block(" switch" ) {
238+ val unpacker = MessagePack .newDefaultUnpacker(data)
239+ unpacker.skipValue(N )
240+ unpacker.hasNext shouldBe false
241+ }
242+ }
243+
236244 }
237245
238246 " parse int data" in {
You can’t perform that action at this time.
0 commit comments