Skip to content

Commit

Permalink
Inline methods
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Feb 17, 2025
1 parent 90ff912 commit fa08b54
Showing 1 changed file with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ public boolean is_normalized() {
case UNKNOWN -> {
Normalizer2 normalizer = Normalizer2.getNFDInstance();
boolean isNormalized = normalizer.isNormalized(toString());
setFcdNormalized(isNormalized);
if (isNormalized) {
fcdNormalized = FcdNormalized.YES;
} else {
fcdNormalized = FcdNormalized.NO;
}
return isNormalized;
}
}
Expand Down Expand Up @@ -212,22 +216,13 @@ String toDisplayString(
return Core_Text_Utils.prettyPrint(str);
}

private void setFcdNormalized(boolean flag) {
if (flag) {
fcdNormalized = FcdNormalized.YES;
} else {
fcdNormalized = FcdNormalized.NO;
}
}

@Override
public String toString() {
Object c = this.contents;
if (c instanceof String s) {
return s;
} else {
return flattenAndSetContent(c);
}
return switch (this.contents) {
case String s -> s;
case ConcatRope r -> flattenAndSetContent(r);
case null, default -> throw new NullPointerException();
};
}

/**
Expand All @@ -238,17 +233,17 @@ public String toString() {
*/
@CompilerDirectives.TruffleBoundary
private String flattenAndSetContent(Object c) {
Deque<Object> workStack = new ArrayDeque<>();
var workStack = new ArrayDeque<Object>();
StringBuilder bldr = new StringBuilder();
workStack.push(c);
while (!workStack.isEmpty()) {
Object item = workStack.pop();
if (item instanceof String) {
bldr.append((String) item);
} else {
ConcatRope rope = (ConcatRope) item;
workStack.push(rope.left());
workStack.push(rope.right());
switch (workStack.pop()) {
case String s -> bldr.append(s);
case ConcatRope rope -> {
workStack.push(rope.right());
workStack.push(rope.left());
}
case null, default -> throw new NullPointerException();
}
}
var result = bldr.toString();
Expand Down

0 comments on commit fa08b54

Please sign in to comment.