Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWEEP: Replace J2N's TripleShift call with C# 11's unsigned right shift operator #1007

Merged
merged 3 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
-->
<Project>
<PropertyGroup>
<!-- According to the docs (https://docs.microsoft.com/en-us/cpp/build/reference/common-macros-for-build-commands-and-properties?view=vs-2019), the
<!-- According to the docs (https://docs.microsoft.com/en-us/cpp/build/reference/common-macros-for-build-commands-and-properties?view=vs-2019), the
SolutionDir is only available when running in the IDE, so we patch to ensure it also works when using dotnet.exe -->
<SolutionDir Condition=" '$(SolutionDir)' == '' ">$(MSBuildThisFileDirectory)</SolutionDir>
</PropertyGroup>

<PropertyGroup>
<LangVersion>9.0</LangVersion>
<LangVersion>11.0</LangVersion>
<GitHubOrganization>apache</GitHubOrganization>
<GitHubProject>lucenenet</GitHubProject>
</PropertyGroup>
Expand All @@ -35,8 +35,8 @@
<PropertyGroup Label="Version of Builds">
<!-- IMPORTANT: VersionPrefix must always be the same as the Lucene version this is based on.
Never increment it for an individual build - only increment this when an entire version's changes
are ported over from Lucene. This is what determines the version of all of the NuGet packages and binaries.
For patching a production build, we will add a 4th segment (4.8.0.1) since it would be confusing to increment to
are ported over from Lucene. This is what determines the version of all of the NuGet packages and binaries.
For patching a production build, we will add a 4th segment (4.8.0.1) since it would be confusing to increment to
4.8.1 if we haven't actually ported over the changes from Lucene 4.8.1. -->
<VersionPrefix>4.8.0</VersionPrefix>

Expand Down Expand Up @@ -85,10 +85,10 @@
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

<!-- Settings to override the above Version of Builds. These can be used to
"freeze" the build number for a release, so whether building within
an IDE or from the commmand line, the version is always what is
in Version.props, if it exists and the PrepareForBuild argument
<!-- Settings to override the above Version of Builds. These can be used to
"freeze" the build number for a release, so whether building within
an IDE or from the commmand line, the version is always what is
in Version.props, if it exists and the PrepareForBuild argument
passed into build.ps1 is 'false'. -->
<Import Project="version.props" Condition="Exists('version.props')" />
</Project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Lucene version compatibility level 4.8.1
using J2N.Numerics;
using Lucene.Net.Diagnostics;
using Lucene.Net.Util;
using System.Diagnostics;
using System.IO;

namespace Lucene.Net.Analysis.CharFilters
Expand Down Expand Up @@ -62,7 +60,7 @@ protected override int Correct(int currentOff)

while (hi >= lo)
{
mid = (lo + hi).TripleShift(1);
mid = (lo + hi) >>> 1;
if (currentOff < offsets[mid])
{
hi = mid - 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Lucene version compatibility level 4.8.1
using J2N.Numerics;
using Lucene.Net.Support;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
Expand All @@ -17,9 +15,9 @@ namespace Lucene.Net.Analysis.Compound.Hyphenation
* 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.
Expand All @@ -31,7 +29,7 @@ namespace Lucene.Net.Analysis.Compound.Hyphenation
/// This tree structure stores the hyphenation patterns in an efficient way for
/// fast lookup. It provides the provides the method to hyphenate a word.
/// <para/>
/// This class has been taken from the Apache FOP project (http://xmlgraphics.apache.org/fop/). They have been slightly modified.
/// This class has been taken from the Apache FOP project (http://xmlgraphics.apache.org/fop/). They have been slightly modified.
///
/// Lucene.NET specific note:
/// If you are going to extend this class by inheriting from it, you should be aware that the
Expand Down Expand Up @@ -109,7 +107,7 @@ protected virtual string UnpackValues(int k)
byte v = m_vspace[k++];
while (v != 0)
{
char c = (char)(v.TripleShift(4) - 1 + '0');
char c = (char)((v >>> 4) - 1 + '0');
buf.Append(c);
c = (char)(v & 0x0f);
if (c == 0)
Expand Down Expand Up @@ -253,7 +251,7 @@ protected virtual byte[] GetValues(int k)
byte v = m_vspace[k++];
while (v != 0)
{
char c = (char)(v.TripleShift(4) - 1);
char c = (char)((v >>> 4) - 1);
buf.Append(c);
c = (char)(v & 0x0f);
if (c == 0)
Expand All @@ -278,7 +276,7 @@ protected virtual byte[] GetValues(int k)
/// interletter values. In other words, it does something like:
/// </para>
/// <code>
/// for (i=0; i&lt;patterns.Length; i++)
/// for (i=0; i&lt;patterns.Length; i++)
/// {
/// if (word.Substring(index).StartsWith(patterns[i], StringComparison.Ordinal))
/// update_interletter_values(patterns[i]);
Expand Down Expand Up @@ -596,4 +594,4 @@ public virtual void AddPattern(string pattern, string ivalue)

// }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Lucene version compatibility level 4.10.4
using J2N;
using J2N.Numerics;
using J2N.Text;
using Lucene.Net.Diagnostics;
using Lucene.Net.Store;
Expand Down Expand Up @@ -1128,7 +1127,7 @@ internal static char[] DecodeFlags(BytesRef b)
{
return CharsRef.EMPTY_CHARS;
}
int len = b.Length.TripleShift(1);
int len = b.Length >>> 1;
char[] flags = new char[len];
int upto = 0;
int end = b.Offset + b.Length;
Expand Down
11 changes: 5 additions & 6 deletions src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Stemmer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Lucene version compatibility level 4.10.4
using J2N.Numerics;
using J2N.Text;
using Lucene.Net.Analysis.Util;
using Lucene.Net.Diagnostics;
Expand Down Expand Up @@ -398,7 +397,7 @@ private IList<CharsRef> Stem(char[] word, int length, int previous, int prevFlag
char stripOrd = (char)(affixReader.ReadInt16() & 0xffff);
int condition = (char)(affixReader.ReadInt16() & 0xffff);
bool crossProduct = (condition & 1) == 1;
condition = condition.TripleShift(1);
condition >>>= 1;
char append = (char)(affixReader.ReadInt16() & 0xffff);

bool compatible;
Expand Down Expand Up @@ -503,7 +502,7 @@ private IList<CharsRef> Stem(char[] word, int length, int previous, int prevFlag
char stripOrd = (char)(affixReader.ReadInt16() & 0xffff);
int condition = (char)(affixReader.ReadInt16() & 0xffff);
bool crossProduct = (condition & 1) == 1;
condition = condition.TripleShift(1);
condition >>>= 1;
char append = (char)(affixReader.ReadInt16() & 0xffff);

bool compatible;
Expand Down Expand Up @@ -618,7 +617,7 @@ internal IList<CharsRef> ApplyAffix(char[] strippedWord, int length, int affix,
affixReader.SkipBytes(2); // strip
int condition = (char)(affixReader.ReadInt16() & 0xffff);
bool crossProduct = (condition & 1) == 1;
condition = condition.TripleShift(1);
condition >>>= 1;
char append = (char)(affixReader.ReadInt16() & 0xffff);

JCG.List<CharsRef> stems = new JCG.List<CharsRef>();
Expand Down Expand Up @@ -689,7 +688,7 @@ internal IList<CharsRef> ApplyAffix(char[] strippedWord, int length, int affix,
if (prefix)
{
// we took away the first prefix.
// COMPLEXPREFIXES = true: combine with a second prefix and another suffix
// COMPLEXPREFIXES = true: combine with a second prefix and another suffix
// COMPLEXPREFIXES = false: combine with a suffix
stems.AddRange(Stem(strippedWord, length, affix, flag, flag, ++recursionDepth, dictionary.complexPrefixes && dictionary.twoStageAffix, true, true, circumfix, caseVariant));
}
Expand Down Expand Up @@ -731,4 +730,4 @@ private static bool HasCrossCheckedFlag(char flag, char[] flags, bool matchEmpty
return (flags.Length == 0 && matchEmpty) || Array.BinarySearch(flags, flag) >= 0;
}
}
}
}
19 changes: 9 additions & 10 deletions src/Lucene.Net.Analysis.Common/Analysis/Synonym/SynonymFilter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Lucene version compatibility level 4.8.1
using J2N;
using J2N.Numerics;
using Lucene.Net.Analysis.TokenAttributes;
using Lucene.Net.Diagnostics;
using Lucene.Net.Store;
Expand Down Expand Up @@ -34,29 +33,29 @@ namespace Lucene.Net.Analysis.Synonym
/// This token stream cannot properly handle position
/// increments != 1, ie, you should place this filter before
/// filtering out stop words.
///
///
/// <para>Note that with the current implementation, parsing is
/// greedy, so whenever multiple parses would apply, the rule
/// starting the earliest and parsing the most tokens wins.
/// For example if you have these rules:
///
///
/// <code>
/// a -> x
/// a b -> y
/// b c d -> z
/// </code>
///
///
/// Then input <c>a b c d e</c> parses to <c>y b c
/// d</c>, ie the 2nd rule "wins" because it started
/// earliest and matched the most input tokens of other rules
/// starting at that point.</para>
///
///
/// <para>A future improvement to this filter could allow
/// non-greedy parsing, such that the 3rd rule would win, and
/// also separately allow multiple parses, such that all 3
/// rules would match, perhaps even on a rule by rule
/// basis.</para>
///
///
/// <para><b>NOTE</b>: when a match occurs, the output tokens
/// associated with the matching rule are "stacked" on top of
/// the input stream (if the rule had
Expand All @@ -69,7 +68,7 @@ namespace Lucene.Net.Analysis.Synonym
/// do so. This limitation is necessary because Lucene's
/// <see cref="TokenStream"/> (and index) cannot yet represent an arbitrary
/// graph.</para>
///
///
/// <para><b>NOTE</b>: If multiple incoming tokens arrive on the
/// same position, only the first token at that position is
/// used for parsing. Subsequent tokens simply pass through
Expand Down Expand Up @@ -260,7 +259,7 @@ public virtual void Add(char[] output, int offset, int len, int endOffset, int p
/// in using <see cref="CultureInfo.InvariantCulture"/>.
/// Note, if you set this to <c>true</c>, its your responsibility to lowercase
/// the input entries when you create the <see cref="SynonymMap"/>.</param>
public SynonymFilter(TokenStream input, SynonymMap synonyms, bool ignoreCase)
public SynonymFilter(TokenStream input, SynonymMap synonyms, bool ignoreCase)
: base(input)
{
termAtt = AddAttribute<ICharTermAttribute>();
Expand Down Expand Up @@ -496,7 +495,7 @@ private void AddOutput(BytesRef bytes, int matchInputLength, int matchEndOffset)

int code = bytesReader.ReadVInt32();
bool keepOrig = (code & 0x1) == 0;
int count = code.TripleShift(1);
int count = code >>> 1;
//System.out.println(" addOutput count=" + count + " keepOrig=" + keepOrig);
for (int outputIDX = 0; outputIDX < count; outputIDX++)
{
Expand Down Expand Up @@ -716,4 +715,4 @@ public override void Reset()
}
}
}
}
}
15 changes: 7 additions & 8 deletions src/Lucene.Net.Analysis.Kuromoji/Dict/BinaryDictionary.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using J2N;
using J2N.IO;
using J2N.Numerics;
using Lucene.Net.Codecs;
using Lucene.Net.Store;
using Lucene.Net.Support;
Expand Down Expand Up @@ -116,7 +115,7 @@ protected BinaryDictionary()
targetMapOffsets[sourceId] = ofs;
sourceId++;
}
accum += val.TripleShift(1);
accum += val >>> 1;
targetMap[ofs] = accum;
}
if (sourceId + 1 != targetMapOffsets.Length)
Expand Down Expand Up @@ -218,12 +217,12 @@ public virtual void LookupWordIds(int sourceId, Int32sRef @ref)

public virtual int GetLeftId(int wordId)
{
return buffer.GetInt16(wordId).TripleShift(3);
return buffer.GetInt16(wordId) >>> 3;
}

public virtual int GetRightId(int wordId)
{
return buffer.GetInt16(wordId).TripleShift(3);
return buffer.GetInt16(wordId) >>> 3;
}

public virtual int GetWordCost(int wordId)
Expand All @@ -237,7 +236,7 @@ public virtual string GetBaseForm(int wordId, char[] surfaceForm, int off, int l
{
int offset = BaseFormOffset(wordId);
int data = buffer.Get(offset++) & 0xff;
int prefix = data.TripleShift(4);
int prefix = data >>> 4;
int suffix = data & 0xF;
char[] text = new char[prefix + suffix];
Arrays.Copy(surfaceForm, off, text, 0, prefix);
Expand All @@ -259,7 +258,7 @@ public virtual string GetReading(int wordId, char[] surface, int off, int len)
{
int offset = ReadingOffset(wordId);
int readingData = buffer.Get(offset++) & 0xff;
return ReadString(offset, readingData.TripleShift(1), (readingData & 1) == 1);
return ReadString(offset, readingData >>> 1, (readingData & 1) == 1);
}
else
{
Expand Down Expand Up @@ -292,7 +291,7 @@ public virtual string GetPronunciation(int wordId, char[] surface, int off, int
{
int offset = PronunciationOffset(wordId);
int pronunciationData = buffer.Get(offset++) & 0xff;
return ReadString(offset, pronunciationData.TripleShift(1), (pronunciationData & 1) == 1);
return ReadString(offset, pronunciationData >>> 1, (pronunciationData & 1) == 1);
}
else
{
Expand Down Expand Up @@ -342,7 +341,7 @@ private int PronunciationOffset(int wordId)
}
else
{
readingLength = readingData.TripleShift(1);
readingLength = readingData >>> 1;
}
return offset + readingLength;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Lucene.Net.Analysis.Kuromoji/Dict/ConnectionCosts.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using J2N.Numerics;
using Lucene.Net.Codecs;
using Lucene.Net.Codecs;
using Lucene.Net.Store;
using Lucene.Net.Support;
using System;
Expand Down Expand Up @@ -53,7 +52,7 @@ private ConnectionCosts()
for (int i = 0; i < a.Length; i++)
{
int raw = @in.ReadVInt32();
accum += raw.TripleShift(1) ^ -(raw & 1);
accum += (raw >>> 1) ^ -(raw & 1);
a[i] = (short)accum;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Lucene.Net.Analysis.SmartCn/Hhmm/PathNode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// lucene version compatibility level: 4.8.1
using J2N.Numerics;
using System;

namespace Lucene.Net.Analysis.Cn.Smart.Hhmm
Expand Down Expand Up @@ -54,7 +53,7 @@ public override int GetHashCode()
result = prime * result + PreNode;
long temp;
temp = J2N.BitConversion.DoubleToInt64Bits(Weight);
result = prime * result + (int)(temp ^ temp.TripleShift(32));
result = prime * result + (int)(temp ^ (temp >>> 32));
return result;
}

Expand Down
3 changes: 1 addition & 2 deletions src/Lucene.Net.Analysis.SmartCn/Hhmm/SegTokenPair.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// lucene version compatibility level: 4.8.1
using J2N.Numerics;
using Lucene.Net.Support;

namespace Lucene.Net.Analysis.Cn.Smart.Hhmm
Expand Down Expand Up @@ -66,7 +65,7 @@ public override int GetHashCode()
result = prime * result + To;
long temp;
temp = J2N.BitConversion.DoubleToInt64Bits(Weight);
result = prime * result + (int)(temp ^ temp.TripleShift(32));
result = prime * result + (int)(temp ^ (temp >>> 32));
return result;
}

Expand Down
Loading
Loading