Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

GTNPORTAL-3571: Improve as much as possible the performance of the Router #924

Open
wants to merge 1 commit into
base: 3.8.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ class BitStack {
private static class Frame {

/** . */
private Frame previous;
Frame previous;

/** . */
private Frame next;
Frame next;

/** . */
private long bits;
long bits;

/** . */
private int cardinality;
int cardinality;

private Frame() {
this(0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

package org.exoplatform.web.controller.router;

import java.io.IOException;
import java.util.BitSet;

import org.exoplatform.commons.utils.CharEncoder;
import org.exoplatform.commons.utils.CharsetCharEncoder;
import org.gatein.common.io.UndeclaredIOException;

import java.io.IOException;
import java.util.BitSet;

/**
* @author <a href="mailto:[email protected]">Julien Viet</a>
*/
Expand Down Expand Up @@ -123,13 +123,15 @@ public final class PercentEncoding {

/** . */
private final BitSet allowed;
private final int length;

private PercentEncoding(BitSet allowed) {
this.allowed = allowed;
this.length = allowed.length();
}

boolean accept(char c) {
return c < allowed.length() && allowed.get(c);
return c < length && allowed.get(c);
}

public void encode(CharSequence s, Appendable appendable) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

package org.exoplatform.web.controller.router;

import org.exoplatform.web.controller.QualifiedName;

import java.util.HashMap;
import java.util.Map;

import org.exoplatform.web.controller.QualifiedName;

/**
* The render context used to compute the rendering of a parameter map.
*
Expand Down Expand Up @@ -75,7 +75,7 @@ public void remove(String match) {
private final Map<QualifiedName, Parameter> parameters;

/** . */
private BitStack stack = new BitStack();
BitStack stack = new BitStack();

/** . */
Regex.Matcher[] matchers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ public String toString() {
private static final RequestParam[] EMPTY_REQUEST_PARAM_ARRAY = new RequestParam[0];

/** . */
private final Router router;
final Router router;

/** . */
private Route parent;
Route parent;

/** . */
private boolean terminal;
Expand All @@ -156,7 +156,7 @@ public String toString() {
private Map<String, RequestParam> requestParamMap;

/** . */
private RequestParam[] requestParamArray;
RequestParam[] requestParamArray;

Route(Router router) {
this.router = router;
Expand Down Expand Up @@ -325,8 +325,9 @@ private RouteMatch _find(RenderContext context) {
// Match first the static parameteters
for (RouteParam param : routeParamArray) {
RenderContext.Parameter entry = context.getParameter(param.name);
if (entry != null && !entry.isMatched() && param.value.equals(entry.getValue())) {
entry.remove(entry.getValue());
String value;
if (entry != null && !entry.isMatched() && param.value.equals(value = entry.getValue())) {
entry.remove(value);
} else {
return null;
}
Expand Down Expand Up @@ -370,8 +371,9 @@ private RouteMatch _find(RenderContext context) {
case PRESERVE_PATH:
for (int j = 0; j < param.matchingRegex.length; j++) {
Regex renderingRegex = param.matchingRegex[j];
if (context.matcher(renderingRegex).matches(s.getValue())) {
matched = param.templatePrefixes[j] + s.getValue() + param.templateSuffixes[j];
String value;
if (context.matcher(renderingRegex).matches(value = s.getValue())) {
matched = param.templatePrefixes[j] + value + param.templateSuffixes[j];
break;
}
}
Expand Down