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

Avoid computing expensive debug info for all checkState() calls #1029

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1029.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: fix
fix:
description: Avoid computing expensive debug info for all checkState() calls
links:
- https://github.com/palantir/palantir-java-format/pull/1029
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.palantir.javaformat.doc;

import com.google.common.base.Preconditions;
import com.palantir.javaformat.PartialInlineability;
import com.palantir.javaformat.doc.StartsWithBreakVisitor.Result;
import java.util.List;
Expand Down Expand Up @@ -69,10 +68,13 @@ public Float visitLevel(Level level) {
return visit(level.getDocs().get(found.getAsInt()));
}
// Otherwise, assert that we encountered a break and move on.
Preconditions.checkState(
StartsWithBreakVisitor.INSTANCE.visit(level) == Result.YES,
"Didn't find expected break at the beginning of level.\n%s",
level.representation(State.startingState()));
if (StartsWithBreakVisitor.INSTANCE.visit(level) != Result.YES) {
// Avoid computing expensive level.representation() if we aren't throwing it in an exception.
throw new IllegalStateException(String.format(
"Didn't find expected break at the beginning of level.\n%s",
level.representation(State.startingState())));
}

return 0f;
}

Expand Down
Loading