Skip to content

Commit

Permalink
Refactor: Remove label usage for improved efficiency
Browse files Browse the repository at this point in the history
  • Loading branch information
KNU-K authored Nov 17, 2024
1 parent cea5d9e commit dc443ec
Showing 1 changed file with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,12 @@ else if (!fullMatch && "**".equals(pattDirs[pattIdxStart])) {
int strLength = (pathIdxEnd - pathIdxStart + 1);
int foundIdx = -1;

strLoop:
for (int i = 0; i <= strLength - patLength; i++) {
for (int j = 0; j < patLength; j++) {
String subPat = pattDirs[pattIdxStart + j + 1];
String subStr = pathDirs[pathIdxStart + i + j];
if (!matchStrings(subPat, subStr, uriTemplateVariables)) {
continue strLoop;
}
MatchContext context = new MatchContext(pattDirs, pathDirs, pattIdxStart, pathIdxStart, uriTemplateVariables );
if(checkSubPatternMatch(context, i, patLength)){
foundIdx = pathIdxStart + i;
break;
}
foundIdx = pathIdxStart + i;
break;
}

if (foundIdx == -1) {
Expand All @@ -340,6 +335,32 @@ else if (!fullMatch && "**".equals(pattDirs[pattIdxStart])) {

return true;
}
private static class MatchContext{
String[] pattDirs;
String[] pathDirs;
int pattIdxStart;
int pathIdxStart;
Map<String, String> uriTemplateVariables;

MatchContext(String[] pattDirs, String[] pathDirs, int pattIdxStart, int pathIdxStart, Map<String, String> uriTemplateVariables) {
this.pattDirs = pattDirs;
this.pathDirs = pathDirs;
this.pattIdxStart = pattIdxStart;
this.pathIdxStart = pathIdxStart;
this.uriTemplateVariables = uriTemplateVariables;
}
}

private boolean checkSubPatternMatch(MatchContext context, int i, int patLength) {
for (int j = 0; j < patLength; j++) {
String subPat = context.pattDirs[context.pattIdxStart + j + 1];
String subStr = context.pathDirs[context.pathIdxStart + i + j];
if (!matchStrings(subPat, subStr, context.uriTemplateVariables)) {
return false;
}
}
return true;
}

private boolean isPotentialMatch(String path, String[] pattDirs) {
if (!this.trimTokens) {
Expand Down

0 comments on commit dc443ec

Please sign in to comment.