Skip to content

Commit

Permalink
Avoid computing expensive debug info for all checkState() calls (#1029)
Browse files Browse the repository at this point in the history
Avoid computing expensive debug info for all checkState() calls
  • Loading branch information
ash211 authored Mar 13, 2024
1 parent 1f62421 commit 9c88122
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
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

0 comments on commit 9c88122

Please sign in to comment.