diff options
author | 2023-02-05 00:13:13 +0100 | |
---|---|---|
committer | 2023-02-05 00:13:13 +0100 | |
commit | 15dcbeff0e28f0d6d3da8702b24f60ac52686609 (patch) | |
tree | 56f0d152a47d0f5649ed2a5453d6879dc292a803 /subprojects/store/src/main/java/tools | |
parent | Performance improvements by replacing hash depth calculation with shifting, i... (diff) | |
download | refinery-15dcbeff0e28f0d6d3da8702b24f60ac52686609.tar.gz refinery-15dcbeff0e28f0d6d3da8702b24f60ac52686609.tar.zst refinery-15dcbeff0e28f0d6d3da8702b24f60ac52686609.zip |
Code quality improvements in nodes
printer appending + empty node stack checking
Diffstat (limited to 'subprojects/store/src/main/java/tools')
-rw-r--r-- | subprojects/store/src/main/java/tools/refinery/store/map/internal/ImmutableNode.java | 7 | ||||
-rw-r--r-- | subprojects/store/src/main/java/tools/refinery/store/map/internal/MutableNode.java | 7 |
2 files changed, 8 insertions, 6 deletions
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/ImmutableNode.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/ImmutableNode.java index e437aceb..914bab08 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/ImmutableNode.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/ImmutableNode.java | |||
@@ -225,6 +225,9 @@ public class ImmutableNode<K, V> extends Node<K, V> { | |||
225 | 225 | ||
226 | // 2. look inside the subnodes | 226 | // 2. look inside the subnodes |
227 | int nodes = Integer.bitCount(this.nodeMap); | 227 | int nodes = Integer.bitCount(this.nodeMap); |
228 | if(cursor.nodeIndexStack.peek()==null) { | ||
229 | throw new IllegalStateException("Cursor moved to the next state when the state is empty."); | ||
230 | } | ||
228 | int newNodeIndex = cursor.nodeIndexStack.peek() + 1; | 231 | int newNodeIndex = cursor.nodeIndexStack.peek() + 1; |
229 | if (newNodeIndex < nodes) { | 232 | if (newNodeIndex < nodes) { |
230 | // 2.1 found next subnode, move down to the subnode | 233 | // 2.1 found next subnode, move down to the subnode |
@@ -252,9 +255,7 @@ public class ImmutableNode<K, V> extends Node<K, V> { | |||
252 | 255 | ||
253 | @Override | 256 | @Override |
254 | public void prettyPrint(StringBuilder builder, int depth, int code) { | 257 | public void prettyPrint(StringBuilder builder, int depth, int code) { |
255 | for (int i = 0; i < depth; i++) { | 258 | builder.append("\t".repeat(Math.max(0, depth))); |
256 | builder.append("\t"); | ||
257 | } | ||
258 | if (code >= 0) { | 259 | if (code >= 0) { |
259 | builder.append(code); | 260 | builder.append(code); |
260 | builder.append(":"); | 261 | builder.append(":"); |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/MutableNode.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/MutableNode.java index 9d15a0d7..cdc66a10 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/MutableNode.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/MutableNode.java | |||
@@ -306,6 +306,9 @@ public class MutableNode<K, V> extends Node<K, V> { | |||
306 | } | 306 | } |
307 | 307 | ||
308 | // 2. look inside the subnodes | 308 | // 2. look inside the subnodes |
309 | if(cursor.nodeIndexStack.peek()==null) { | ||
310 | throw new IllegalStateException("Cursor moved to the next state when the state is empty."); | ||
311 | } | ||
309 | for (int index = cursor.nodeIndexStack.peek() + 1; index < FACTOR; index++) { | 312 | for (int index = cursor.nodeIndexStack.peek() + 1; index < FACTOR; index++) { |
310 | if (this.content[index * 2] == null && this.content[index * 2 + 1] != null) { | 313 | if (this.content[index * 2] == null && this.content[index * 2 + 1] != null) { |
311 | // 2.1 found next subnode, move down to the subnode | 314 | // 2.1 found next subnode, move down to the subnode |
@@ -335,9 +338,7 @@ public class MutableNode<K, V> extends Node<K, V> { | |||
335 | 338 | ||
336 | @Override | 339 | @Override |
337 | public void prettyPrint(StringBuilder builder, int depth, int code) { | 340 | public void prettyPrint(StringBuilder builder, int depth, int code) { |
338 | for (int i = 0; i < depth; i++) { | 341 | builder.append("\t".repeat(Math.max(0, depth))); |
339 | builder.append("\t"); | ||
340 | } | ||
341 | if (code >= 0) { | 342 | if (code >= 0) { |
342 | builder.append(code); | 343 | builder.append(code); |
343 | builder.append(":"); | 344 | builder.append(":"); |