Skip to content

Commit

Permalink
Issue #7891 - Better group match optimization logic
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed May 11, 2022
1 parent 498b5c3 commit fc05341
Showing 1 changed file with 13 additions and 11 deletions.
Expand Up @@ -147,11 +147,17 @@ public MatchedResource<E> getMatched(String path)
MatchedPath matchedPath;
PathSpecGroup lastGroup = null;

boolean skipRestOfGroup = false;
// Search all the mappings
for (MappedResource<E> mr : _mappings)
{
boolean skipMatch = false;
PathSpecGroup group = mr.getPathSpec().getGroup();
if (group == lastGroup && skipRestOfGroup)
{
continue; // skip
}

// Run servlet spec optimizations on first hit of specific groups
if (group != lastGroup)
{
// New group in list, so let's look for an optimization
Expand All @@ -178,7 +184,7 @@ public MatchedResource<E> getMatched(String path)
i--;
}
// If we reached here, there's NO optimized EXACT Match possible, skip simple match below
skipMatch = true;
skipRestOfGroup = true;
}
break;
}
Expand All @@ -201,7 +207,7 @@ public MatchedResource<E> getMatched(String path)
i--;
}
// If we reached here, there's NO optimized PREFIX Match possible, skip simple match below
skipMatch = true;
skipRestOfGroup = true;
}
break;
}
Expand All @@ -223,7 +229,7 @@ public MatchedResource<E> getMatched(String path)
return new MatchedResource<>(candidate.getResource(), candidate.getPathSpec(), matchedPath);
}
// If we reached here, there's NO optimized SUFFIX Match possible, skip simple match below
skipMatch = true;
skipRestOfGroup = true;
}
break;
}
Expand All @@ -232,13 +238,9 @@ public MatchedResource<E> getMatched(String path)
}
}

// Only perform simple match if optimized match lets us
if (!skipMatch)
{
matchedPath = mr.getPathSpec().matched(path);
if (matchedPath != null)
return new MatchedResource<>(mr.getResource(), mr.getPathSpec(), matchedPath);
}
matchedPath = mr.getPathSpec().matched(path);
if (matchedPath != null)
return new MatchedResource<>(mr.getResource(), mr.getPathSpec(), matchedPath);

lastGroup = group;
}
Expand Down

0 comments on commit fc05341

Please sign in to comment.