You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2020/06/30 21:50:47 UTC

[lucenenet] 11/27: Automaton patches

This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git

commit 55e44c7986e3956054805a50feb1afd194451cb7
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Sun Jun 28 22:51:50 2020 +0700

    Automaton patches
---
 src/Lucene.Net/Util/Automaton/Automaton.cs       | 10 ++++------
 src/Lucene.Net/Util/Automaton/BasicOperations.cs | 21 ++++++++-------------
 src/Lucene.Net/Util/Automaton/SortedIntSet.cs    |  3 +--
 src/Lucene.Net/Util/Automaton/State.cs           |  5 ++---
 4 files changed, 15 insertions(+), 24 deletions(-)

diff --git a/src/Lucene.Net/Util/Automaton/Automaton.cs b/src/Lucene.Net/Util/Automaton/Automaton.cs
index 49d5c0c..acbbd97 100644
--- a/src/Lucene.Net/Util/Automaton/Automaton.cs
+++ b/src/Lucene.Net/Util/Automaton/Automaton.cs
@@ -281,9 +281,8 @@ namespace Lucene.Net.Util.Automaton
                             t.to.number = upto;
                             if (upto == states.Length)
                             {
-                                State[] newArray = new State[ArrayUtil.Oversize(1 + upto, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
-                                Array.Copy(states, 0, newArray, 0, upto);
-                                states = newArray;
+                                // LUCENENET: Resize rather than copy
+                                Array.Resize(ref states, ArrayUtil.Oversize(1 + upto, RamUsageEstimator.NUM_BYTES_OBJECT_REF));
                             }
                             states[upto] = t.to;
                             upto++;
@@ -292,9 +291,8 @@ namespace Lucene.Net.Util.Automaton
                 }
                 if (states.Length != upto)
                 {
-                    State[] newArray = new State[upto];
-                    Array.Copy(states, 0, newArray, 0, upto);
-                    states = newArray;
+                    // LUCENENET: Resize rather than copy
+                    Array.Resize(ref states, upto);
                 }
                 numberedStates = states;
             }
diff --git a/src/Lucene.Net/Util/Automaton/BasicOperations.cs b/src/Lucene.Net/Util/Automaton/BasicOperations.cs
index 96dc55a..7bc4c19 100644
--- a/src/Lucene.Net/Util/Automaton/BasicOperations.cs
+++ b/src/Lucene.Net/Util/Automaton/BasicOperations.cs
@@ -631,9 +631,8 @@ namespace Lucene.Net.Util.Automaton
             {
                 if (transitions.Length == count)
                 {
-                    Transition[] newArray = new Transition[ArrayUtil.Oversize(1 + count, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
-                    Array.Copy(transitions, 0, newArray, 0, count);
-                    transitions = newArray;
+                    // LUCENENET: Resize rather than copy
+                    Array.Resize(ref transitions, ArrayUtil.Oversize(1 + count, RamUsageEstimator.NUM_BYTES_OBJECT_REF));
                 }
                 transitions[count++] = t;
             }
@@ -684,9 +683,8 @@ namespace Lucene.Net.Util.Automaton
                 // 1st time we are seeing this point
                 if (count == points.Length)
                 {
-                    PointTransitions[] newArray = new PointTransitions[ArrayUtil.Oversize(1 + count, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
-                    Array.Copy(points, 0, newArray, 0, count);
-                    points = newArray;
+                    // LUCENENET: Resize rather than copy
+                    Array.Resize(ref points, ArrayUtil.Oversize(1 + count, RamUsageEstimator.NUM_BYTES_OBJECT_REF));
                 }
                 PointTransitions points0 = points[count];
                 if (points0 == null)
@@ -703,8 +701,7 @@ namespace Lucene.Net.Util.Automaton
                 if (useHash)
                 {
                     int? pi = point;
-                    PointTransitions p;
-                    if (!map.TryGetValue(pi, out p))
+                    if (!map.TryGetValue(pi, out PointTransitions p))
                     {
                         p = Next(point);
                         map[pi] = p;
@@ -856,8 +853,7 @@ namespace Lucene.Net.Util.Automaton
 
                         statesSet.ComputeHash();
 
-                        State q;
-                        if (!newstate.TryGetValue(statesSet.ToFrozenInt32Set(), out q) || q == null)
+                        if (!newstate.TryGetValue(statesSet.ToFrozenInt32Set(), out State q) || q == null)
                         {
                             q = new State();
 
@@ -865,9 +861,8 @@ namespace Lucene.Net.Util.Automaton
                             worklist.AddLast(p);
                             if (newStateUpto == newStatesArray.Length)
                             {
-                                State[] newArray = new State[ArrayUtil.Oversize(1 + newStateUpto, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
-                                Array.Copy(newStatesArray, 0, newArray, 0, newStateUpto);
-                                newStatesArray = newArray;
+                                // LUCENENET: Resize rather than copy
+                                Array.Resize(ref newStatesArray, ArrayUtil.Oversize(1 + newStateUpto, RamUsageEstimator.NUM_BYTES_OBJECT_REF));
                             }
                             newStatesArray[newStateUpto] = q;
                             q.number = newStateUpto;
diff --git a/src/Lucene.Net/Util/Automaton/SortedIntSet.cs b/src/Lucene.Net/Util/Automaton/SortedIntSet.cs
index 0f44258..994c964 100644
--- a/src/Lucene.Net/Util/Automaton/SortedIntSet.cs
+++ b/src/Lucene.Net/Util/Automaton/SortedIntSet.cs
@@ -59,8 +59,7 @@ namespace Lucene.Net.Util.Automaton
             if (useTreeMap)
             {
                 int key = num;
-                int val;
-                if (!map.TryGetValue(key, out val))
+                if (!map.TryGetValue(key, out int val))
                 {
                     map[key] = 1;
                 }
diff --git a/src/Lucene.Net/Util/Automaton/State.cs b/src/Lucene.Net/Util/Automaton/State.cs
index 1df6c98..7b123ef 100644
--- a/src/Lucene.Net/Util/Automaton/State.cs
+++ b/src/Lucene.Net/Util/Automaton/State.cs
@@ -172,9 +172,8 @@ namespace Lucene.Net.Util.Automaton
         {
             if (numTransitions == transitionsArray.Length)
             {
-                Transition[] newArray = new Transition[ArrayUtil.Oversize(1 + numTransitions, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
-                Array.Copy(transitionsArray, 0, newArray, 0, numTransitions);
-                transitionsArray = newArray;
+                // LUCENENET: Resize rather than copy
+                Array.Resize(ref transitionsArray, ArrayUtil.Oversize(1 + numTransitions, RamUsageEstimator.NUM_BYTES_OBJECT_REF));
             }
             transitionsArray[numTransitions++] = t;
         }