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 f0ec411198844af3a5b2ab45f6e408116d19cfe7 Author: Shad Storhaug <[email protected]> AuthorDate: Thu Dec 9 09:26:28 2021 +0700 Lucene.Net.Support: Factored out ICallable<V> and ICompletionService<V> interfaces, as they are not needed --- .../Suggest/LookupBenchmarkTest.cs | 12 ++++---- src/Lucene.Net/Search/IndexSearcher.cs | 20 ++++++++------ src/Lucene.Net/Support/ICallable.cs | 24 ---------------- .../Support/Threading/ICompletionService.cs | 32 ---------------------- .../Threading/TaskSchedulerCompletionService.cs | 9 +++--- 5 files changed, 22 insertions(+), 75 deletions(-) diff --git a/src/Lucene.Net.Tests.Suggest/Suggest/LookupBenchmarkTest.cs b/src/Lucene.Net.Tests.Suggest/Suggest/LookupBenchmarkTest.cs index 9b1442f..e4669f5 100644 --- a/src/Lucene.Net.Tests.Suggest/Suggest/LookupBenchmarkTest.cs +++ b/src/Lucene.Net.Tests.Suggest/Suggest/LookupBenchmarkTest.cs @@ -120,7 +120,7 @@ namespace Lucene.Net.Search.Suggest Console.WriteLine("-- construction time"); foreach (var cls in benchmarkClasses) { - BenchmarkResult result = Measure(new CallableIntHelper(this, cls)); + BenchmarkResult result = Measure(new CallableIntHelper(this, cls).Call); Console.WriteLine( string.Format(CultureInfo.InvariantCulture, "{0,15}s input: {1}, time[ms]: {2}" /*"%-15s input: %d, time[ms]: %s"*/, @@ -130,7 +130,7 @@ namespace Lucene.Net.Search.Suggest } } - private class CallableIntHelper : ICallable<int> + private class CallableIntHelper // LUCENENET: no need for ICallable<V> interface { private readonly Type cls; private readonly LookupBenchmarkTest outerInstance; @@ -250,7 +250,7 @@ namespace Lucene.Net.Search.Suggest input.Add(sub); } - BenchmarkResult result = Measure(new PerformanceTestCallableIntHelper(this, input, lookup)); + BenchmarkResult result = Measure(new PerformanceTestCallableIntHelper(this, input, lookup).Call); Console.WriteLine( string.Format(CultureInfo.InvariantCulture, "{0,15}s queries: {1}, time[ms]: {2}, ~kQPS: {3:#.0}" /*"%-15s queries: %d, time[ms]: %s, ~kQPS: %.0f"*/, @@ -261,7 +261,7 @@ namespace Lucene.Net.Search.Suggest } } - internal class PerformanceTestCallableIntHelper : ICallable<int> + internal class PerformanceTestCallableIntHelper // LUCENENET: no need for ICallable<V> interface { private readonly IEnumerable<string> input; private readonly Lookup lookup; @@ -288,7 +288,7 @@ namespace Lucene.Net.Search.Suggest /** * Do the measurements. */ - private BenchmarkResult Measure(ICallable<int> callable) + private BenchmarkResult Measure(Func<int> callable) { double NANOS_PER_MS = 1000000; @@ -298,7 +298,7 @@ namespace Lucene.Net.Search.Suggest for (int i = 0; i < warmup + rounds; i++) { long start = J2N.Time.NanoTime(); - guard = Convert.ToInt32(callable.Call()); + guard = Convert.ToInt32(callable()); times.Add((J2N.Time.NanoTime() - start) / NANOS_PER_MS ); } return new BenchmarkResult(times, warmup, rounds); diff --git a/src/Lucene.Net/Search/IndexSearcher.cs b/src/Lucene.Net/Search/IndexSearcher.cs index 712de33..8c18328 100644 --- a/src/Lucene.Net/Search/IndexSearcher.cs +++ b/src/Lucene.Net/Search/IndexSearcher.cs @@ -456,7 +456,7 @@ namespace Lucene.Net.Search for (int i = 0; i < m_leafSlices.Length; i++) // search each sub { - runner.Submit(new SearcherCallableNoSort(@lock, this, m_leafSlices[i], weight, after, nDocs, hq)); + runner.Submit(new SearcherCallableNoSort(@lock, this, m_leafSlices[i], weight, after, nDocs, hq).Call); } int totalHits = 0; @@ -549,10 +549,12 @@ namespace Lucene.Net.Search ReentrantLock @lock = new ReentrantLock(); ExecutionHelper<TopFieldDocs> runner = new ExecutionHelper<TopFieldDocs>(executor); + for (int i = 0; i < m_leafSlices.Length; i++) // search each leaf slice { - runner.Submit(new SearcherCallableWithSort(@lock, this, m_leafSlices[i], weight, after, nDocs, topCollector, sort, doDocScores, doMaxScore)); + runner.Submit(new SearcherCallableWithSort(@lock, this, m_leafSlices[i], weight, after, nDocs, topCollector, sort, doDocScores, doMaxScore).Call); } + int totalHits = 0; float maxScore = float.NegativeInfinity; foreach (TopFieldDocs topFieldDocs in runner) @@ -722,7 +724,7 @@ namespace Lucene.Net.Search /// <summary> /// A thread subclass for searching a single searchable /// </summary> - private sealed class SearcherCallableNoSort : ICallable<TopDocs> + private sealed class SearcherCallableNoSort // LUCENENET: no need for ICallable<V> interface { private readonly ReentrantLock @lock; private readonly IndexSearcher searcher; @@ -771,7 +773,7 @@ namespace Lucene.Net.Search /// <summary> /// A thread subclass for searching a single searchable /// </summary> - private sealed class SearcherCallableWithSort : ICallable<TopFieldDocs> + private sealed class SearcherCallableWithSort // LUCENENET: no need for ICallable<V> interface { private readonly ReentrantLock @lock; private readonly IndexSearcher searcher; @@ -834,13 +836,13 @@ namespace Lucene.Net.Search } /// <summary> - /// A helper class that wraps a <see cref="ICompletionService{T}"/> and provides an - /// iterable interface to the completed <see cref="ICallable{V}"/> instances. + /// A helper class that wraps a <see cref="TaskSchedulerCompletionService{T}"/> and provides an + /// iterable interface to the completed <see cref="Func{T}"/> delegates. /// </summary> - /// <typeparam name="T">the type of the <see cref="ICallable{V}"/> return value</typeparam> + /// <typeparam name="T">the type of the <see cref="Func{T}"/> return value</typeparam> private sealed class ExecutionHelper<T> : IEnumerator<T>, IEnumerable<T> { - private readonly ICompletionService<T> service; + private readonly TaskSchedulerCompletionService<T> service; private int numTasks; private T current; @@ -857,7 +859,7 @@ namespace Lucene.Net.Search { } - public void Submit(ICallable<T> task) + public void Submit(Func<T> task) { this.service.Submit(task); ++numTasks; diff --git a/src/Lucene.Net/Support/ICallable.cs b/src/Lucene.Net/Support/ICallable.cs deleted file mode 100644 index fb8554f..0000000 --- a/src/Lucene.Net/Support/ICallable.cs +++ /dev/null @@ -1,24 +0,0 @@ -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - internal interface ICallable<V> - { - V Call(); - } -} \ No newline at end of file diff --git a/src/Lucene.Net/Support/Threading/ICompletionService.cs b/src/Lucene.Net/Support/Threading/ICompletionService.cs deleted file mode 100644 index 2a8e8a9..0000000 --- a/src/Lucene.Net/Support/Threading/ICompletionService.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Threading.Tasks; - -namespace Lucene.Net.Support.Threading -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - internal interface ICompletionService<V> - { - //Task<V> Poll(); - - //Task<V> Poll(long timeout, TimeUnit unit); - - Task<V> Submit(ICallable<V> task); - - Task<V> Take(); - } -} \ No newline at end of file diff --git a/src/Lucene.Net/Support/Threading/TaskSchedulerCompletionService.cs b/src/Lucene.Net/Support/Threading/TaskSchedulerCompletionService.cs index abd1cfd..4de7358 100644 --- a/src/Lucene.Net/Support/Threading/TaskSchedulerCompletionService.cs +++ b/src/Lucene.Net/Support/Threading/TaskSchedulerCompletionService.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Threading.Tasks; namespace Lucene.Net.Support.Threading @@ -20,7 +21,7 @@ namespace Lucene.Net.Support.Threading * limitations under the License. */ - internal class TaskSchedulerCompletionService<T> : ICompletionService<T> + internal class TaskSchedulerCompletionService<T> { private readonly TaskFactory<T> factory; private readonly Queue<Task<T>> taskQueue = new Queue<Task<T>>(); @@ -30,9 +31,9 @@ namespace Lucene.Net.Support.Threading this.factory = new TaskFactory<T>(scheduler ?? TaskScheduler.Default); } - public Task<T> Submit(ICallable<T> task) + public Task<T> Submit(Func<T> task) { - var t = factory.StartNew(task.Call); + var t = factory.StartNew(task); taskQueue.Enqueue(t); return t; }
