lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [Lucene.Net] svn commit: r1104574 - in /incubator/lucene.net/branches/Lucene.Net_2_9_4g: src/core/Analysis/ src/core/Index/ src/core/Util/ test/core/Util/
Date Tue, 17 May 2011 21:38:29 GMT
Author: digy
Date: Tue May 17 21:38:29 2011
New Revision: 1104574

URL: http://svn.apache.org/viewvc?rev=1104574&view=rev
Log:
[LUCENENET-412] WeakDictionary Part 4(final)

Modified:
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/Analyzer.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/FieldsReader.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/SegmentReader.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/TermInfosReader.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/CloseableThreadLocal.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Util/TestCloseableThreadLocal.cs

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/Analyzer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/Analyzer.cs?rev=1104574&r1=1104573&r2=1104574&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/Analyzer.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/Analyzer.cs Tue May
17 21:38:29 2011
@@ -19,7 +19,7 @@ using System;
 
 using Fieldable = Lucene.Net.Documents.Fieldable;
 using AlreadyClosedException = Lucene.Net.Store.AlreadyClosedException;
-using CloseableThreadLocal = Lucene.Net.Util.CloseableThreadLocal;
+using Lucene.Net.Util;
 
 namespace Lucene.Net.Analysis
 {
@@ -51,7 +51,7 @@ namespace Lucene.Net.Analysis
 			return TokenStream(fieldName, reader);
 		}
 		
-		private CloseableThreadLocal tokenStreams = new CloseableThreadLocal();
+		private CloseableThreadLocal<object> tokenStreams = new CloseableThreadLocal<object>();
 		
 		/// <summary>Used by Analyzers that implement reusableTokenStream
 		/// to retrieve previously saved TokenStreams for re-use

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/FieldsReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/FieldsReader.cs?rev=1104574&r1=1104573&r2=1104574&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/FieldsReader.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/FieldsReader.cs Tue May
17 21:38:29 2011
@@ -23,9 +23,10 @@ using AlreadyClosedException = Lucene.Ne
 using BufferedIndexInput = Lucene.Net.Store.BufferedIndexInput;
 using Directory = Lucene.Net.Store.Directory;
 using IndexInput = Lucene.Net.Store.IndexInput;
-using CloseableThreadLocal = Lucene.Net.Util.CloseableThreadLocal;
 using StringHelper = Lucene.Net.Util.StringHelper;
 
+using Lucene.Net.Util;
+
 namespace Lucene.Net.Index
 {
 	
@@ -58,8 +59,8 @@ namespace Lucene.Net.Index
 		// The docID offset where our docs begin in the index
 		// file.  This will be 0 if we have our own private file.
 		private int docStoreOffset;
-		
-		private CloseableThreadLocal fieldsStreamTL = new CloseableThreadLocal();
+
+        private CloseableThreadLocal<IndexInput> fieldsStreamTL = new CloseableThreadLocal<IndexInput>();
 		private bool isOriginal = false;
 
         //DIGY
@@ -557,7 +558,7 @@ namespace Lucene.Net.Index
 			
 			private IndexInput GetFieldStream()
 			{
-				IndexInput localFieldsStream = (IndexInput) Enclosing_Instance.fieldsStreamTL.Get();
+				IndexInput localFieldsStream = Enclosing_Instance.fieldsStreamTL.Get();
 				if (localFieldsStream == null)
 				{
 					localFieldsStream = (IndexInput) Enclosing_Instance.cloneableFieldsStream.Clone();

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/SegmentReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/SegmentReader.cs?rev=1104574&r1=1104573&r2=1104574&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/SegmentReader.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/SegmentReader.cs Tue May
17 21:38:29 2011
@@ -25,9 +25,10 @@ using Directory = Lucene.Net.Store.Direc
 using IndexInput = Lucene.Net.Store.IndexInput;
 using IndexOutput = Lucene.Net.Store.IndexOutput;
 using BitVector = Lucene.Net.Util.BitVector;
-using CloseableThreadLocal = Lucene.Net.Util.CloseableThreadLocal;
 using DefaultSimilarity = Lucene.Net.Search.DefaultSimilarity;
 
+using Lucene.Net.Util;
+
 namespace Lucene.Net.Index
 {
 	
@@ -50,9 +51,9 @@ namespace Lucene.Net.Index
 		
 		private SegmentInfo si;
 		private int readBufferSize;
-		
-		internal CloseableThreadLocal fieldsReaderLocal;
-		internal CloseableThreadLocal termVectorsLocal = new CloseableThreadLocal();
+
+        internal CloseableThreadLocal<FieldsReader> fieldsReaderLocal;
+        internal CloseableThreadLocal<TermVectorsReader> termVectorsLocal = new CloseableThreadLocal<TermVectorsReader>();
 		
 		internal BitVector deletedDocs = null;
 		internal Ref deletedDocsRef = null;
@@ -392,7 +393,7 @@ namespace Lucene.Net.Index
 		}
 		
 		/// <summary> Sets the initial value </summary>
-		private class FieldsReaderLocal:CloseableThreadLocal
+        private class FieldsReaderLocal : CloseableThreadLocal<FieldsReader>
 		{
 			public FieldsReaderLocal(SegmentReader enclosingInstance)
 			{
@@ -411,9 +412,9 @@ namespace Lucene.Net.Index
 				}
 				
 			}
-			public /*protected internal*/ override System.Object InitialValue()
+            public /*protected internal*/ override FieldsReader InitialValue()
 			{
-				return Enclosing_Instance.core.GetFieldsReaderOrig().Clone();
+                return (FieldsReader)Enclosing_Instance.core.GetFieldsReaderOrig().Clone();
 			}
 		}
 		
@@ -1146,7 +1147,7 @@ namespace Lucene.Net.Index
         
 		internal virtual FieldsReader GetFieldsReader()
 		{
-			return (FieldsReader) fieldsReaderLocal.Get();
+			return fieldsReaderLocal.Get();
 		}
 		
 		protected internal override void  DoClose()
@@ -1567,7 +1568,7 @@ namespace Lucene.Net.Index
 		/// </returns>
 		internal virtual TermVectorsReader GetTermVectorsReader()
 		{
-			TermVectorsReader tvReader = (TermVectorsReader) termVectorsLocal.Get();
+			TermVectorsReader tvReader = termVectorsLocal.Get();
 			if (tvReader == null)
 			{
 				TermVectorsReader orig = core.GetTermVectorsReaderOrig();

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/TermInfosReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/TermInfosReader.cs?rev=1104574&r1=1104573&r2=1104574&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/TermInfosReader.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/TermInfosReader.cs Tue
May 17 21:38:29 2011
@@ -18,9 +18,10 @@
 using System;
 
 using Directory = Lucene.Net.Store.Directory;
-using CloseableThreadLocal = Lucene.Net.Util.CloseableThreadLocal;
 using SimpleLRUCache = Lucene.Net.Util.Cache.SimpleLRUCache<Lucene.Net.Index.Term,Lucene.Net.Index.TermInfo>;
 
+using Lucene.Net.Util;
+
 namespace Lucene.Net.Index
 {
 
@@ -34,8 +35,8 @@ namespace Lucene.Net.Index
 		private Directory directory;
 		private System.String segment;
 		private FieldInfos fieldInfos;
-		
-		private CloseableThreadLocal threadResources = new CloseableThreadLocal();
+
+        private CloseableThreadLocal<ThreadResources> threadResources = new CloseableThreadLocal<ThreadResources>();
 		private SegmentTermEnum origEnum;
 		private long size;
 		
@@ -154,7 +155,7 @@ namespace Lucene.Net.Index
 		
 		private ThreadResources GetThreadResources()
 		{
-			ThreadResources resources = (ThreadResources) threadResources.Get();
+			ThreadResources resources = threadResources.Get();
 			if (resources == null)
 			{
 				resources = new ThreadResources();

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/CloseableThreadLocal.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/CloseableThreadLocal.cs?rev=1104574&r1=1104573&r2=1104574&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/CloseableThreadLocal.cs
(original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/CloseableThreadLocal.cs
Tue May 17 21:38:29 2011
@@ -41,20 +41,20 @@ namespace Lucene.Net.Util
 	/// reclaim space by objects stored in it. 
 	/// </summary>
 	
-	public class CloseableThreadLocal
+	public class CloseableThreadLocal<T>
 	{
 		
 		[ThreadStatic]
-        static Support.WeakHashTable slots;
+        static Support.WeakDictionary<CloseableThreadLocal<T>, T> slots;
 		
-		public /*protected internal*/ virtual System.Object InitialValue()
+		public virtual T InitialValue()
 		{
-			return null;
+			return default(T);
 		}
 
-        public virtual System.Object Get()
+        public virtual T Get()
         {
-            object value;
+            T value;
 
             if (slots == null)
             {
@@ -77,10 +77,10 @@ namespace Lucene.Net.Util
             }
         }
 		
-		public virtual void  Set(System.Object object_Renamed)
+		public virtual void  Set(T object_Renamed)
 		{
             if (slots == null)
-                slots = new Support.WeakHashTable();
+                slots = new Support.WeakDictionary<CloseableThreadLocal<T>, T>();
 
 			slots[this] = object_Renamed;	
 		}

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Util/TestCloseableThreadLocal.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Util/TestCloseableThreadLocal.cs?rev=1104574&r1=1104573&r2=1104574&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Util/TestCloseableThreadLocal.cs
(original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Util/TestCloseableThreadLocal.cs
Tue May 17 21:38:29 2011
@@ -31,7 +31,7 @@ namespace Lucene.Net.Util
 		public virtual void  TestInitValue()
 		{
 			InitValueThreadLocal tl = new InitValueThreadLocal(this);
-			System.String str = (System.String) tl.Get();
+			System.String str = tl.Get();
 			Assert.AreEqual(TEST_VALUE, str);
 		}
 		
@@ -40,8 +40,8 @@ namespace Lucene.Net.Util
 		{
 			// Tests that null can be set as a valid value (LUCENE-1805). This
 			// previously failed in get().
-			CloseableThreadLocal ctl = new CloseableThreadLocal();
-			ctl.Set((System.Object) null);
+			CloseableThreadLocal<object> ctl = new CloseableThreadLocal<object>();
+			ctl.Set(null);
 			Assert.IsNull(ctl.Get());
 		}
 		
@@ -50,31 +50,21 @@ namespace Lucene.Net.Util
 		{
 			// LUCENE-1805: make sure default get returns null,
 			// twice in a row
-			CloseableThreadLocal ctl = new CloseableThreadLocal();
+			CloseableThreadLocal<object> ctl = new CloseableThreadLocal<object>();
 			Assert.IsNull(ctl.Get());
 			Assert.IsNull(ctl.Get());
 		}
 		
-		public class InitValueThreadLocal:CloseableThreadLocal
+		public class InitValueThreadLocal:CloseableThreadLocal<string>
 		{
 			public InitValueThreadLocal(TestCloseableThreadLocal enclosingInstance)
 			{
-				InitBlock(enclosingInstance);
-			}
-			private void  InitBlock(TestCloseableThreadLocal enclosingInstance)
-			{
-				this.enclosingInstance = enclosingInstance;
+                this.enclosingInstance = enclosingInstance;
 			}
+			
 			private TestCloseableThreadLocal enclosingInstance;
-			public TestCloseableThreadLocal Enclosing_Instance
-			{
-				get
-				{
-					return enclosingInstance;
-				}
-				
-			}
-			public /*protected internal*/ override System.Object InitialValue()
+			
+			public override string InitialValue()
 			{
 				return Lucene.Net.Util.TestCloseableThreadLocal.TEST_VALUE;
 			}



Mime
View raw message