NightOwl888 commented on code in PR #957: URL: https://github.com/apache/lucenenet/pull/957#discussion_r1720571019
########## src/Lucene.Net/Search/NumericRangeQuery.cs: ########## @@ -487,12 +488,12 @@ protected override sealed AcceptStatus Accept(BytesRef term) { while (currentUpperBound is null || termComp.Compare(term, currentUpperBound) > 0) { - if (rangeBounds.Count == 0) + if (!rangeBounds.TryPeek(out BytesRef rangeBound)) Review Comment: This appears to be a performance optimization to exit the loop as soon as possible. https://github.com/apache/lucene/blob/releases/lucene-solr/4.8.0/lucene/core/src/java/org/apache/lucene/search/NumericRangeQuery.java#L520 Please revert the changes to this method. ########## src/Lucene.Net/Support/QueueExtensions.cs: ########## @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +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. + */ + + /// <summary> + /// Extensions to <see cref="Queue{T}"/> + /// </summary> + internal static class QueueExtensions + { +#if !FEATURE_QUEUE_TRYDEQUEUE_TRYPEEK + /// <summary> + /// Removes the object at the beginning of the <see cref="Queue{T}"/>, + /// and copies it to the <paramref name="result"/> parameter. + /// </summary> + /// <typeparam name="T">The type of element in the <see cref="Queue{T}"/></typeparam> + /// <param name="queue">The <see cref="Queue{T}"/> to be checked</param> + /// <param name="result">The removed object</param> + /// <returns><c>true</c> if the object was successfully removed; <c>false</c> if the <see cref="Queue{T}"/> is empty.</returns> + /// <exception cref="ArgumentNullException"></exception> + [MethodImpl(MethodImplOptions.AggressiveInlining)] Review Comment: I believe this is a bit too much code to make inlining worth it. It will only apply to legacy frameworks, anyway. Please remove `[MethodImpl(MethodImplOptions.AggressiveInlining)]` both here and on `TryPeek()`. ########## src/Lucene.Net.Analysis.Common/Analysis/Shingle/ShingleFilter.cs: ########## @@ -508,11 +509,7 @@ public override void End() /// <exception cref="IOException"> if there's a problem getting the next token </exception> private void ShiftInputWindow() { - InputWindowToken firstToken = null; - if (inputWindow.Count > 0) - { - firstToken = inputWindow.Dequeue(); - } + inputWindow.TryDequeue(out InputWindowToken firstToken); Review Comment: https://github.com/apache/lucene/blob/releases/lucene-solr/4.8.1/lucene/analysis/common/src/java/org/apache/lucene/analysis/shingle/ShingleFilter.java#L454-L457 Since this doesn't align very well with the Java source, lets add a comment so it is clear that firstToken will be null if the queue is empty. ```c# inputWindow.TryDequeue(out InputWindowToken firstToken); // LUCENENET: firstToken will be null if the queue is empty ``` ########## src/Lucene.Net.Tests/Support/QueueExtensionsTests.cs: ########## @@ -0,0 +1,94 @@ +using System.Collections.Generic; +using NUnit.Framework; + +using Lucene.Net.Attributes; +using Lucene.Net.Util; +using Lucene.Net.Support; +using System; + + +namespace Lucene.Net +{ + /* + * 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. + */ + + public class QueueExtensionsTests : LuceneTestCase + { +#if !FEATURE_QUEUE_TRYDEQUEUE_TRYPEEK + [Test, LuceneNetSpecific] + public void TryDequeue_ThrowsWhenQueueNull() + { + Queue<int> queue = null; + var ex = Assert.Throws<ArgumentNullException>(() => queue.TryDequeue(out int _)); + Assert.That(ex.ParamName, Is.EqualTo("queue")); Review Comment: `Assert.That()` is painfully slow. In fact, we don't use any NUnit asserts because they cause our tests to take about twice as long. Please add the following alias after the list of usings: ```c# using Assert = Lucene.Net.TestFramework.Assert; ``` And change each `Assert.That()` in this file to use `Assert.AreEqual()`. We have optimized overloads of these asserts that accept value types. ########## src/Lucene.Net/Index/IndexWriter.cs: ########## @@ -2690,17 +2690,12 @@ public virtual MergePolicy.OneMerge NextMerge() UninterruptableMonitor.Enter(this); try { - if (pendingMerges.Count == 0) Review Comment: I believe in this case, this is a performance optimization to give up the lock as soon as possible on an empty queue. https://github.com/apache/lucene/blob/releases/lucene-solr/4.8.0/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java#L2047-L2056 Please revert the changes in this method, as it is easier to follow as-is. Also, please add a comment after the method declaration: ```c# public virtual MergePolicy.OneMerge NextMerge() // LUCENENET TODO: API - Revert name to GetNextMerge() to match Java ``` We will need to review more of the API before renaming to make certain that it is consistent with other method names. ########## src/Lucene.Net.Analysis.Phonetic/DoubleMetaphoneFilter.cs: ########## @@ -52,12 +53,11 @@ public DoubleMetaphoneFilter(TokenStream input, int maxCodeLength, bool inject) public override bool IncrementToken() { - for (;;) + for (; ; ) Review Comment: As much as I dislike using a for loop this way, it is what was done in Java. https://github.com/apache/lucene/blob/releases/lucene-solr/4.8.1/lucene/analysis/phonetic/src/java/org/apache/lucene/analysis/phonetic/DoubleMetaphoneFilter.java#L53 But the original source didn't have spaces. So could we please remove them again? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@lucenenet.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org