Apache Lucene open-source search software
Reversing in place rewritten slightly. Seems more intuitive to me now.
Dawid Weiss6ef7db2eaa38
diff --git a/lucene/src/java/org/apache/lucene/util/automaton/fst/FST.java b/lucene/src/java/org/apache/lucene/util/automaton/fst/FST.javaindex dde66270873..512d07f28d7 100644--- a/lucene/src/java/org/apache/lucene/util/automaton/fst/FST.java+++ b/lucene/src/java/org/apache/lucene/util/automaton/fst/FST.java@@ -446,25 +446,17 @@ public class FST<T> {// reverse bytes in-place; we do this so that the// "BIT_TARGET_NEXT" opto can work, ie, it reads the// node just before the current one- final int endAddress = writer.posWrite;- final int stopAt = (endAddress - startAddress)/2;- int upto = 0;- while (upto < stopAt) {- final byte b = bytes[startAddress+upto];- bytes[startAddress+upto] = bytes[endAddress-upto-1];- bytes[endAddress-upto-1] = b;- upto++;- }+ final int endAddress = lastFrozenNode = writer.posWrite - 1;- lastFrozenNode = endAddress - 1;- /*- System.out.println(" return node addr=" + (endAddress-1));- for(int i=endAddress-1;i>=startAddress;i--) {- System.out.println(" bytes[" + i + "]=" + bytes[i]);+ int left = startAddress;+ int right = endAddress;+ while (left < right) {+ final byte b = bytes[left];+ bytes[left++] = bytes[right];+ bytes[right--] = b;}- */- return endAddress-1;+ return endAddress;}/** Fills virtual 'start' arc, ie, an empty incoming arc to