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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user