Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.concurrent.ConcurrentHashMap;
import software.amazon.smithy.java.cbor.CborParser.Token;
import software.amazon.smithy.java.core.schema.Schema;
import software.amazon.smithy.java.core.schema.TraitKey;
import software.amazon.smithy.java.core.serde.SerializationException;
import software.amazon.smithy.java.core.serde.ShapeDeserializer;
import software.amazon.smithy.java.core.serde.document.Document;
Expand Down Expand Up @@ -357,6 +358,10 @@ public Instant readTimestamp(Schema schema) {
@Override
public <T> void readStruct(Schema schema, T state, StructMemberConsumer<T> consumer) {
byte token = parser.currentToken();
if (schema.hasTrait(TraitKey.UNIT_TYPE_TRAIT) && token == Token.FINISHED) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should reverse the order, the second condition is much cheaper and if its false it would be a faster short-circuit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I will post a follow up for this.

// Empty input — treat as empty struct with no members.
return;
}
if (token != Token.START_OBJECT) {
throw badType("struct", token);
}
Expand Down