PERFORMANCE: Lucene.Net.Facet: Moved scratch BytesRef instances outside of the loops they were nested in so they can be reused (like in Lucene)
diff --git a/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs b/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs
index 37e44fc..e81f1ac 100644
--- a/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs
+++ b/src/Lucene.Net.Facet/SortedSet/DefaultSortedSetDocValuesReaderState.cs
@@ -66,6 +66,7 @@
// each term/ord it's assigning as it goes...
string lastDim = null;
int startOrd = -1;
+ BytesRef spare = new BytesRef();
// TODO: this approach can work for full hierarchy?;
// TaxoReader can't do this since ords are not in
@@ -73,12 +74,11 @@
// support arbitrary hierarchy:
for (int ord = 0; ord < valueCount; ord++)
{
- BytesRef term = new BytesRef();
- dv.LookupOrd(ord, term);
- string[] components = FacetsConfig.StringToPath(term.Utf8ToString());
+ dv.LookupOrd(ord, spare);
+ string[] components = FacetsConfig.StringToPath(spare.Utf8ToString());
if (components.Length != 2)
{
- throw new ArgumentException("this class can only handle 2 level hierarchy (dim/value); got: " + Arrays.ToString(components) + " " + term.Utf8ToString());
+ throw new ArgumentException("this class can only handle 2 level hierarchy (dim/value); got: " + Arrays.ToString(components) + " " + spare.Utf8ToString());
}
if (!components[0].Equals(lastDim, StringComparison.Ordinal))
{
diff --git a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs
index 23c32cd..a71f1d5 100644
--- a/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs
+++ b/src/Lucene.Net.Facet/SortedSet/SortedSetDocValuesFacetCounts.cs
@@ -136,13 +136,14 @@
return null;
}
+ var scratch = new BytesRef();
+
LabelAndValue[] labelValues = new LabelAndValue[q.Count];
for (int i = labelValues.Length - 1; i >= 0; i--)
{
TopOrdAndInt32Queue.OrdAndValue ordAndValue = q.Pop();
- var term = new BytesRef();
- dv.LookupOrd(ordAndValue.Ord, term);
- string[] parts = FacetsConfig.StringToPath(term.Utf8ToString());
+ dv.LookupOrd(ordAndValue.Ord, scratch);
+ string[] parts = FacetsConfig.StringToPath(scratch.Utf8ToString());
labelValues[i] = new LabelAndValue(parts[1], ordAndValue.Value);
}
diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs
index 44ca367..72d35ac 100644
--- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs
+++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumFloatAssociations.cs
@@ -65,6 +65,7 @@
continue;
}
+ BytesRef scratch = new BytesRef();
DocIdSetIterator docs = hits.Bits.GetIterator();
int doc;
@@ -73,11 +74,10 @@
//System.out.println(" doc=" + doc);
// TODO: use OrdinalsReader? we'd need to add a
// BytesRef getAssociation()?
- BytesRef bytesRef = new BytesRef();
- dv.Get(doc, bytesRef);
- byte[] bytes = bytesRef.Bytes;
- int end = bytesRef.Offset + bytesRef.Length;
- int offset = bytesRef.Offset;
+ dv.Get(doc, scratch);
+ byte[] bytes = scratch.Bytes;
+ int end = scratch.Offset + scratch.Length;
+ int offset = scratch.Offset;
while (offset < end)
{
int ord = ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) |
diff --git a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs
index 6804818..cb4d17f 100644
--- a/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs
+++ b/src/Lucene.Net.Facet/Taxonomy/TaxonomyFacetSumIntAssociations.cs
@@ -65,6 +65,7 @@
continue;
}
+ BytesRef scratch = new BytesRef();
DocIdSetIterator docs = hits.Bits.GetIterator();
int doc;
@@ -73,11 +74,10 @@
//System.out.println(" doc=" + doc);
// TODO: use OrdinalsReader? we'd need to add a
// BytesRef getAssociation()?
- BytesRef bytesRef = new BytesRef();
- dv.Get(doc, bytesRef);
- byte[] bytes = bytesRef.Bytes;
- int end = bytesRef.Offset + bytesRef.Length;
- int offset = bytesRef.Offset;
+ dv.Get(doc, scratch);
+ byte[] bytes = scratch.Bytes;
+ int end = scratch.Offset + scratch.Length;
+ int offset = scratch.Offset;
while (offset < end)
{
int ord = ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) |