lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [06/20] lucenenet git commit: Lucene.Net.Codecs.Sep.IntIndexOutput: implemented .NET dispose pattern
Date Sun, 02 Apr 2017 07:06:06 GMT
Lucene.Net.Codecs.Sep.IntIndexOutput: implemented .NET dispose pattern


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/92c591b5
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/92c591b5
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/92c591b5

Branch: refs/heads/api-work
Commit: 92c591b52ccdc1a0d6dde7e0eafe65b443c12601
Parents: a8502e3
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Sun Apr 2 09:43:17 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Sun Apr 2 11:58:31 2017 +0700

----------------------------------------------------------------------
 .../IntBlock/FixedIntBlockIndexOutput.cs        | 23 ++++++++-------
 .../IntBlock/VariableIntBlockIndexOutput.cs     | 31 +++++++++++---------
 src/Lucene.Net.Codecs/Sep/IntIndexOutput.cs     |  9 +++++-
 .../Codecs/MockSep/MockSingleIntIndexOutput.cs  |  7 +++--
 4 files changed, 43 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/92c591b5/src/Lucene.Net.Codecs/IntBlock/FixedIntBlockIndexOutput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/IntBlock/FixedIntBlockIndexOutput.cs b/src/Lucene.Net.Codecs/IntBlock/FixedIntBlockIndexOutput.cs
index 76bde79..a0d7eb7 100644
--- a/src/Lucene.Net.Codecs/IntBlock/FixedIntBlockIndexOutput.cs
+++ b/src/Lucene.Net.Codecs/IntBlock/FixedIntBlockIndexOutput.cs
@@ -133,20 +133,23 @@ namespace Lucene.Net.Codecs.IntBlock
             }
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            try
+            if (disposing)
             {
-                if (upto > 0)
+                try
                 {
-                    // NOTE: entries in the block after current upto are
-                    // invalid
-                    FlushBlock();
+                    if (upto > 0)
+                    {
+                        // NOTE: entries in the block after current upto are
+                        // invalid
+                        FlushBlock();
+                    }
+                }
+                finally
+                {
+                    m_output.Dispose();
                 }
-            }
-            finally
-            {
-                m_output.Dispose();
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/92c591b5/src/Lucene.Net.Codecs/IntBlock/VariableIntBlockIndexOutput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/IntBlock/VariableIntBlockIndexOutput.cs b/src/Lucene.Net.Codecs/IntBlock/VariableIntBlockIndexOutput.cs
index ce391e5..f26a3bc 100644
--- a/src/Lucene.Net.Codecs/IntBlock/VariableIntBlockIndexOutput.cs
+++ b/src/Lucene.Net.Codecs/IntBlock/VariableIntBlockIndexOutput.cs
@@ -140,24 +140,27 @@ namespace Lucene.Net.Codecs.IntBlock
             Debug.Assert(upto >= 0);
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            try
+            if (disposing)
             {
-                if (hitExcDuringWrite) return;
-
-                // stuff 0s in until the "real" data is flushed:
-                var stuffed = 0;
-                while (upto > stuffed)
+                try
                 {
-                    upto -= Add(0) - 1;
-                    Debug.Assert(upto >= 0);
-                    stuffed += 1;
+                    if (hitExcDuringWrite) return;
+
+                    // stuff 0s in until the "real" data is flushed:
+                    var stuffed = 0;
+                    while (upto > stuffed)
+                    {
+                        upto -= Add(0) - 1;
+                        Debug.Assert(upto >= 0);
+                        stuffed += 1;
+                    }
+                }
+                finally
+                {
+                    m_output.Dispose();
                 }
-            }
-            finally
-            {
-                m_output.Dispose();
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/92c591b5/src/Lucene.Net.Codecs/Sep/IntIndexOutput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Sep/IntIndexOutput.cs b/src/Lucene.Net.Codecs/Sep/IntIndexOutput.cs
index f182895..5d97def 100644
--- a/src/Lucene.Net.Codecs/Sep/IntIndexOutput.cs
+++ b/src/Lucene.Net.Codecs/Sep/IntIndexOutput.cs
@@ -64,6 +64,13 @@ namespace Lucene.Net.Codecs.Sep
         /// </summary>
         public abstract Index GetIndex();
 
-        public abstract void Dispose(); // LUCENENET TODO: Implement disposable pattern
+        // LUCENENET specific - implementing proper dispose pattern
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+
+        protected abstract void Dispose(bool disposing);
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/92c591b5/src/Lucene.Net.TestFramework/Codecs/MockSep/MockSingleIntIndexOutput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Codecs/MockSep/MockSingleIntIndexOutput.cs b/src/Lucene.Net.TestFramework/Codecs/MockSep/MockSingleIntIndexOutput.cs
index 8ee7c44..5154b53 100644
--- a/src/Lucene.Net.TestFramework/Codecs/MockSep/MockSingleIntIndexOutput.cs
+++ b/src/Lucene.Net.TestFramework/Codecs/MockSep/MockSingleIntIndexOutput.cs
@@ -45,9 +45,12 @@ namespace Lucene.Net.Codecs.MockSep
             return new MockSingleIntIndexOutputIndex(this);
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            @out.Dispose();
+            if (disposing)
+            {
+                @out.Dispose();
+            }
         }
 
         public override string ToString()


Mime
View raw message