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


The following commit(s) were added to refs/heads/master by this push:
     new 63e1053b6 SWEEP: Reviewed usage of atomic numeric type methods (#927)
63e1053b6 is described below

commit 63e1053b6cad1b874563400fbe83a708d5c0fa17
Author: Shad Storhaug <[email protected]>
AuthorDate: Mon Mar 11 23:37:01 2024 +0700

    SWEEP: Reviewed usage of atomic numeric type methods (#927)
    
    * SWEEP: Reviewed all applications of .AddAndGet() methods from atomic 
numeric classes
    
    * SWEEP: Reviewed all applications of .GetAndAdd() methods from atomic 
numeric classes
    
    * SWEEP: Reviewed all applications of .IncrementAndGet(), 
.GetAndIncrement(), .DecrementAndGet(), and .GetAndDecrement() from atomic 
numeric classes. Closes #917.
---
 src/Lucene.Net.Replicator/LocalReplicator.cs                        | 5 +++--
 .../Codecs/RAMOnly/RAMOnlyPostingsFormat.cs                         | 6 +++---
 src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs          | 4 ++--
 src/Lucene.Net.Tests/Search/TestBooleanOr.cs                        | 2 +-
 src/Lucene.Net/Store/RAMFile.cs                                     | 4 ++--
 5 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/Lucene.Net.Replicator/LocalReplicator.cs 
b/src/Lucene.Net.Replicator/LocalReplicator.cs
index 756657066..a7c06b7df 100644
--- a/src/Lucene.Net.Replicator/LocalReplicator.cs
+++ b/src/Lucene.Net.Replicator/LocalReplicator.cs
@@ -3,6 +3,7 @@ using Lucene.Net.Support.Threading;
 using System;
 using System.Collections.Generic;
 using System.Diagnostics;
+using System.Globalization;
 using System.IO;
 using System.Linq;
 
@@ -189,7 +190,7 @@ namespace Lucene.Net.Replicator
                 // currentVersion is either null or older than latest 
published revision
                 currentRevision.IncRef();
 
-                string sessionID = sessionToken.IncrementAndGet().ToString();
+                string sessionID = 
sessionToken.IncrementAndGet().ToString(CultureInfo.InvariantCulture);
                 SessionToken token = new SessionToken(sessionID, 
currentRevision.Revision);
                 sessions[sessionID] = new ReplicationSession(token, 
currentRevision);
                 return token;
@@ -329,4 +330,4 @@ namespace Lucene.Net.Replicator
             }
         }
     }
-}
\ No newline at end of file
+}
diff --git 
a/src/Lucene.Net.TestFramework/Codecs/RAMOnly/RAMOnlyPostingsFormat.cs 
b/src/Lucene.Net.TestFramework/Codecs/RAMOnly/RAMOnlyPostingsFormat.cs
index badefe6a6..6f198afc4 100644
--- a/src/Lucene.Net.TestFramework/Codecs/RAMOnly/RAMOnlyPostingsFormat.cs
+++ b/src/Lucene.Net.TestFramework/Codecs/RAMOnly/RAMOnlyPostingsFormat.cs
@@ -572,7 +572,7 @@ namespace Lucene.Net.Codecs.RAMOnly
         // Holds all indexes created, keyed by the ID assigned in 
fieldsConsumer
         private readonly IDictionary<int, RAMPostings> state = new 
Dictionary<int, RAMPostings>();
 
-        private readonly AtomicInt64 nextID = new AtomicInt64();
+        private readonly AtomicInt32 nextID = new AtomicInt32();
 
         private readonly string RAM_ONLY_NAME = "RAMOnly";
         private const int VERSION_START = 0;
@@ -582,7 +582,7 @@ namespace Lucene.Net.Codecs.RAMOnly
 
         public override FieldsConsumer FieldsConsumer(SegmentWriteState 
writeState)
         {
-            int id = (int)nextID.GetAndIncrement();
+            int id = nextID.GetAndIncrement();
 
             // TODO -- ok to do this up front instead of
             // on close....?  should be ok?
@@ -659,4 +659,4 @@ namespace Lucene.Net.Codecs.RAMOnly
             }
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs 
b/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
index dc226fa69..0c756b4b7 100644
--- a/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
+++ b/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
@@ -704,7 +704,7 @@ namespace Lucene.Net.Store
                     {
                         if (existing != null)
                         {
-                            
ramdir.m_sizeInBytes.AddAndGet(-existing.GetSizeInBytes()); // LUCENENET: 
GetAndAdd in Lucene, but we are not using the value
+                            
ramdir.m_sizeInBytes.GetAndAdd(-existing.GetSizeInBytes());
                             existing.directory = null;
                         }
                         ramdir.m_fileMap[name] = file;
@@ -1558,4 +1558,4 @@ namespace Lucene.Net.Store
         }
 #endif
     }
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestBooleanOr.cs 
b/src/Lucene.Net.Tests/Search/TestBooleanOr.cs
index 74971e428..243be1e39 100644
--- a/src/Lucene.Net.Tests/Search/TestBooleanOr.cs
+++ b/src/Lucene.Net.Tests/Search/TestBooleanOr.cs
@@ -205,7 +205,7 @@ namespace Lucene.Net.Search
             while (end.Value < docCount)
             {
                 int inc = TestUtil.NextInt32(Random, 1, 1000);
-                end.AddAndGet(inc);
+                end.GetAndAdd(inc);
                 scorer.Score(c, end);
             }
 
diff --git a/src/Lucene.Net/Store/RAMFile.cs b/src/Lucene.Net/Store/RAMFile.cs
index 11b512df6..ddebcd6b2 100644
--- a/src/Lucene.Net/Store/RAMFile.cs
+++ b/src/Lucene.Net/Store/RAMFile.cs
@@ -90,7 +90,7 @@ namespace Lucene.Net.Store
                 UninterruptableMonitor.Exit(this);
             }
 
-            directory?.m_sizeInBytes.AddAndGet(size);
+            directory?.m_sizeInBytes.GetAndAdd(size);
             return buffer;
         }
 
@@ -146,4 +146,4 @@ namespace Lucene.Net.Store
             }
         }
     }
-}
\ No newline at end of file
+}

Reply via email to