aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2021-01-10 12:23:57 +0100
committerJon Marius Venstad <venstad@gmail.com>2021-01-10 12:23:57 +0100
commita0a55270b4b370238ee949eef62c9c69e82fd76b (patch)
treece5fe04ee748eb4ea9812523fa87d0e5d53a629e /container-search/src/main/java
parenta8fcb9a0eadd03887fb8efd1602c00e71ed9b261 (diff)
Clean up
Diffstat (limited to 'container-search/src/main/java')
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/AllValuesQueryProfileVisitor.java4
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/DimensionValues.java3
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/PrefixQueryProfileVisitor.java6
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java4
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java7
5 files changed, 11 insertions, 13 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/AllValuesQueryProfileVisitor.java b/container-search/src/main/java/com/yahoo/search/query/profile/AllValuesQueryProfileVisitor.java
index 40e22e8bcb5..b24bf1195eb 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/AllValuesQueryProfileVisitor.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/AllValuesQueryProfileVisitor.java
@@ -16,7 +16,7 @@ final class AllValuesQueryProfileVisitor extends PrefixQueryProfileVisitor {
private final Map<String, ValueWithSource> values = new HashMap<>();
/* Lists all values starting at prefix */
- public AllValuesQueryProfileVisitor(CompoundName prefix, Map<CompoundName, Map<String, CompoundName>> pathCache) {
+ public AllValuesQueryProfileVisitor(CompoundName prefix, CompoundNameChildCache pathCache) {
super(prefix, pathCache);
}
@@ -43,7 +43,7 @@ final class AllValuesQueryProfileVisitor extends PrefixQueryProfileVisitor {
QueryProfile owner,
DimensionValues variant,
DimensionBinding binding) {
- CompoundName fullName = cache.computeIfAbsent(currentPrefix, __ -> new HashMap<>()).computeIfAbsent(key, currentPrefix::append);
+ CompoundName fullName = cache.append(currentPrefix, key);
ValueWithSource existing = values.get(fullName.toString());
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/DimensionValues.java b/container-search/src/main/java/com/yahoo/search/query/profile/DimensionValues.java
index 641ccdb3e10..f3c4548c491 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/DimensionValues.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/DimensionValues.java
@@ -77,11 +77,10 @@ public class DimensionValues implements Comparable<DimensionValues> {
}
@Override
- // TODO jonmv: this is an asymmetrical equals — find usages and rename
public boolean equals(Object o) {
if (this == o) return true;
if ( ! (o instanceof DimensionValues)) return false;
- DimensionValues other = (DimensionValues)o;
+ DimensionValues other = (DimensionValues) o;
for (int i = 0; i < this.size() || i < other.size(); i++) {
if (get(i) == null) {
if (other.get(i) != null) return false;
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/PrefixQueryProfileVisitor.java b/container-search/src/main/java/com/yahoo/search/query/profile/PrefixQueryProfileVisitor.java
index 6077e6ae7e0..b53fc4f96f2 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/PrefixQueryProfileVisitor.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/PrefixQueryProfileVisitor.java
@@ -15,7 +15,7 @@ import java.util.Map;
*/
abstract class PrefixQueryProfileVisitor extends QueryProfileVisitor {
- protected final Map<CompoundName, Map<String, CompoundName>> cache;
+ protected final CompoundNameChildCache cache;
/** Only call onValue/onQueryProfile for nodes having this prefix */
private final CompoundName prefix;
@@ -26,7 +26,7 @@ abstract class PrefixQueryProfileVisitor extends QueryProfileVisitor {
private int prefixComponentIndex = -1;
- public PrefixQueryProfileVisitor(CompoundName prefix, Map<CompoundName, Map<String, CompoundName>> cache) {
+ public PrefixQueryProfileVisitor(CompoundName prefix, CompoundNameChildCache cache) {
if (prefix == null)
prefix = CompoundName.empty;
this.prefix = prefix;
@@ -52,7 +52,7 @@ abstract class PrefixQueryProfileVisitor extends QueryProfileVisitor {
if (prefixComponentIndex++ < prefix.size()) return true; // we're in the given prefix, which should not be included in the name
if ( ! name.isEmpty()) {
currentPrefixes.push(currentPrefix);
- currentPrefix = cache.computeIfAbsent(currentPrefix, __ -> new HashMap<>()).computeIfAbsent(name, currentPrefix::append);
+ currentPrefix = cache.append(currentPrefix, name);
}
return true;
}
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java
index 1978740014c..4371955ae63 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java
@@ -265,11 +265,11 @@ public class QueryProfile extends FreezableSimpleComponent implements Cloneable
}
AllValuesQueryProfileVisitor visitValues(CompoundName prefix, Map<String, String> context) {
- return visitValues(prefix, context, new HashMap<>());
+ return visitValues(prefix, context, new CompoundNameChildCache());
}
AllValuesQueryProfileVisitor visitValues(CompoundName prefix, Map<String, String> context,
- Map<CompoundName, Map<String, CompoundName>> pathCache) {
+ CompoundNameChildCache pathCache) {
AllValuesQueryProfileVisitor visitor = new AllValuesQueryProfileVisitor(prefix, pathCache);
accept(visitor, DimensionBinding.createFrom(getDimensions(), context), null);
return visitor;
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java
index 24426b379e9..29a997a75dd 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileCompiler.java
@@ -49,14 +49,13 @@ public class QueryProfileCompiler {
variants.add(new DimensionBindingForPath(DimensionBinding.nullBinding, CompoundName.empty)); // if this contains no variants
log.fine(() -> "Compiling " + in + " having " + variants.size() + " variants");
- Map<CompoundName, Map<String, CompoundName>> pathCache = new HashMap<>();
+ CompoundNameChildCache pathCache = new CompoundNameChildCache();
Map<DimensionBinding, Binding> bindingCache = new HashMap<>();
for (var variant : variants) {
log.finer(() -> "Compiling variant " + variant);
Binding variantBinding = bindingCache.computeIfAbsent(variant.binding(), Binding::createFrom);
for (var entry : in.visitValues(variant.path(), variant.binding().getContext(), pathCache).valuesWithSource().entrySet()) {
- CompoundName fullName = pathCache.computeIfAbsent(variant.path(), __ -> new HashMap<>())
- .computeIfAbsent(entry.getKey(), variant.path()::append);
+ CompoundName fullName = pathCache.append(variant.path, entry.getKey());
values.put(fullName, variantBinding, entry.getValue());
if (entry.getValue().isUnoverridable())
unoverridables.put(fullName, variantBinding, Boolean.TRUE);
@@ -122,7 +121,7 @@ public class QueryProfileCompiler {
trie.forEachPrefixAndChildren((prefixes, childBindings) -> {
Set<DimensionBinding> processed = new HashSet<>();
for (DimensionBindingForPath prefix : prefixes)
- if (processed.add(prefix.binding())) // Only compute once for similar bindings, since path is equals.
+ if (processed.add(prefix.binding())) // Only compute once for similar bindings, since path is equal.
if (hasWildcardBeforeEnd(prefix.binding()))
for (DimensionBinding childBinding : childBindings)
if (childBinding != prefix.binding()) {