Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use nextSource().readAll(blackhole()) for fast skip #1234

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ZacSweers
Copy link
Collaborator

No description provided.

@ZacSweers
Copy link
Collaborator Author

ZacSweers commented Sep 20, 2020

Currently fails a number of tests for me locally, which seems surprising

image

@ZacSweers ZacSweers marked this pull request as draft September 20, 2020 22:13
@cketti
Copy link

cketti commented Sep 21, 2020

The following snippet uses the existing skip behavior for simple values and only defers to nextSource() for objects and arrays. Passes all tests on my machine.

  @Override
  public void skipValue() throws IOException {
    if (failOnUnknown) {
      throw new JsonDataException("Cannot skip unexpected " + peek() + " at " + getPath());
    }
    int p = peeked;
    if (p == PEEKED_NONE) {
      p = doPeek();
    }

    if (p == PEEKED_BEGIN_ARRAY || p == PEEKED_BEGIN_OBJECT) {
      nextSource().readAll(Okio.blackhole());
      valueSource.discard();
      valueSource = null;
      stackSize--;
    } else if (p == PEEKED_UNQUOTED_NAME || p == PEEKED_UNQUOTED) {
      skipUnquotedValue();
    } else if (p == PEEKED_DOUBLE_QUOTED || p == PEEKED_DOUBLE_QUOTED_NAME) {
      skipQuotedValue(DOUBLE_QUOTE_OR_SLASH);
    } else if (p == PEEKED_SINGLE_QUOTED || p == PEEKED_SINGLE_QUOTED_NAME) {
      skipQuotedValue(SINGLE_QUOTE_OR_SLASH);
    } else if (p == PEEKED_NUMBER) {
      buffer.skip(peekedNumberLength);
    } else if (p == PEEKED_END_ARRAY || p == PEEKED_END_OBJECT || p == PEEKED_EOF) {
      throw new JsonDataException("Expected a value but was " + peek() + " at path " + getPath());
    }

    peeked = PEEKED_NONE;
    pathIndices[stackSize - 1]++;
    pathNames[stackSize - 1] = "null";
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants