Cache resourcePath in PermissionBackend

resourcePath() is used to deduplicate PermissionBackendConditions and
possible executed a number of times in equality checks. This commit adds
some local caching to reduce garbage.

Change-Id: I10af9143137efcc3bd0ac1e152a57614a4dc6231
This commit is contained in:
Patrick Hiesel
2018-01-29 17:24:50 +01:00
parent d93390efd8
commit 4dd4775962
3 changed files with 22 additions and 6 deletions

View File

@@ -283,6 +283,7 @@ class ChangeControl {
private class ForChangeImpl extends ForChange {
private ChangeData cd;
private Map<String, PermissionRange> labels;
private String resourcePath;
ForChangeImpl(@Nullable ChangeData cd, @Nullable Provider<ReviewDb> db) {
this.cd = cd;
@@ -320,9 +321,13 @@ class ChangeControl {
@Override
public String resourcePath() {
return String.format(
"/projects/%s/+changes/%s",
getProjectControl().getProjectState().getName(), changeData().getId().get());
if (resourcePath == null) {
resourcePath =
String.format(
"/projects/%s/+changes/%s",
getProjectControl().getProjectState().getName(), changeData().getId().get());
}
return resourcePath;
}
@Override

View File

@@ -312,6 +312,8 @@ class ProjectControl {
}
private class ForProjectImpl extends ForProject {
private String resourcePath;
@Override
public CurrentUser user() {
return getUser();
@@ -324,7 +326,10 @@ class ProjectControl {
@Override
public String resourcePath() {
return "/projects/" + getProjectState().getName();
if (resourcePath == null) {
resourcePath = "/projects/" + getProjectState().getName();
}
return resourcePath;
}
@Override

View File

@@ -431,6 +431,8 @@ class RefControl {
}
private class ForRefImpl extends ForRef {
private String resourcePath;
@Override
public CurrentUser user() {
return getUser();
@@ -443,8 +445,12 @@ class RefControl {
@Override
public String resourcePath() {
return String.format(
"/projects/%s/+refs/%s", getProjectControl().getProjectState().getName(), refName);
if (resourcePath == null) {
resourcePath =
String.format(
"/projects/%s/+refs/%s", getProjectControl().getProjectState().getName(), refName);
}
return resourcePath;
}
@Override