mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11:11 +00:00
Revert fast params in a Trie
This commit is contained in:
parent
1326d76936
commit
c8eaa955c3
1 changed files with 14 additions and 28 deletions
|
|
@ -38,35 +38,20 @@ public class Trie {
|
|||
return decode(new String(chars, begin, end - begin), hasPercent, hasPlus);
|
||||
}
|
||||
|
||||
public static final class Match {
|
||||
final private Object[] params;
|
||||
public static class Match {
|
||||
public IPersistentMap params;
|
||||
public final Object data;
|
||||
private int i = 0;
|
||||
|
||||
public Match(Integer size, Object data) {
|
||||
this.params = new Object[size];
|
||||
public Match(IPersistentMap params, Object data) {
|
||||
this.params = params;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void assoc(Keyword key, Object value) {
|
||||
params[i] = key;
|
||||
params[i + 1] = value;
|
||||
i += 2;
|
||||
}
|
||||
|
||||
public IPersistentMap params() {
|
||||
return new PersistentArrayMap(params);
|
||||
}
|
||||
|
||||
Match copy() {
|
||||
return new Match(params.length, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
Map<Object, Object> m = new HashMap<>();
|
||||
m.put(Keyword.intern("data"), data);
|
||||
m.put(Keyword.intern("params"), params());
|
||||
m.put(Keyword.intern("params"), params);
|
||||
return m.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -131,13 +116,13 @@ public class Trie {
|
|||
private final Match match;
|
||||
|
||||
DataMatcher(IPersistentMap params, Object data) {
|
||||
this.match = new Match(params.count() * 2, data);
|
||||
this.match = new Match(params, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Match match(int i, int max, char[] path) {
|
||||
if (i == max) {
|
||||
return match.copy();
|
||||
return match;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
@ -190,7 +175,7 @@ public class Trie {
|
|||
}
|
||||
final Match m = child.match(stop, max, path);
|
||||
if (m != null) {
|
||||
m.assoc(key, decode(new String(path, i, stop - i), hasPercent, hasPlus));
|
||||
m.params = m.params.assoc(key, decode(new String(path, i, stop - i), hasPercent, hasPlus));
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
|
@ -219,18 +204,19 @@ public class Trie {
|
|||
|
||||
static final class CatchAllMatcher implements Matcher {
|
||||
private final Keyword parameter;
|
||||
private final Match match;
|
||||
private final IPersistentMap params;
|
||||
private final Object data;
|
||||
|
||||
CatchAllMatcher(Keyword parameter, IPersistentMap params, Object data) {
|
||||
this.match = new Match(params.count() * 2, data);
|
||||
this.parameter = parameter;
|
||||
this.params = params;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Match match(int i, int max, char[] path) {
|
||||
if (i <= max) {
|
||||
match.copy().assoc(parameter, decode(path, i, max));
|
||||
return match;
|
||||
return new Match(params.assoc(parameter, decode(path, i, max)), data);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
@ -247,7 +233,7 @@ public class Trie {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" + parameter + " " + new DataMatcher(null, match.data) + "]";
|
||||
return "[" + parameter + " " + new DataMatcher(null, data) + "]";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue