Cache the path of VFileEvent to avoid recomputing it for every listener

This commit is contained in:
Kirill Likhodedov
2017-08-18 11:14:22 +03:00
parent d1a06b3d80
commit fcde9ad60e
7 changed files with 14 additions and 7 deletions
@@ -61,7 +61,7 @@ public class VFileContentChangeEvent extends VFileEvent {
@NotNull
@Override
public String getPath() {
protected String computePath() {
return myFile.getPath();
}
@@ -59,7 +59,7 @@ public class VFileCopyEvent extends VFileEvent {
@NotNull
@Override
public String getPath() {
protected String computePath() {
return myNewParent.getPath() + "/" + myNewChildName;
}
@@ -63,7 +63,7 @@ public class VFileCreateEvent extends VFileEvent {
@NotNull
@Override
public String getPath() {
protected String computePath() {
return myParent.getPath() + "/" + myChildName;
}
@@ -47,7 +47,7 @@ public class VFileDeleteEvent extends VFileEvent {
@NotNull
@Override
public String getPath() {
protected String computePath() {
return myFile.getPath();
}
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.vfs.newvfs.events;
import com.intellij.openapi.util.AtomicNotNullLazyValue;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileSystem;
import org.jetbrains.annotations.NotNull;
@@ -26,6 +27,7 @@ import org.jetbrains.annotations.Nullable;
public abstract class VFileEvent {
private final boolean myIsFromRefresh;
private final Object myRequestor;
@NotNull private final AtomicNotNullLazyValue<String> myPath = AtomicNotNullLazyValue.createValue(this::computePath);
public VFileEvent(Object requestor, final boolean isFromRefresh) {
myRequestor = requestor;
@@ -41,7 +43,12 @@ public abstract class VFileEvent {
}
@NotNull
public abstract String getPath();
public String getPath() {
return myPath.getValue();
}
@NotNull
protected abstract String computePath();
/**
* Returns the VirtualFile which this event belongs to.
@@ -59,7 +59,7 @@ public class VFileMoveEvent extends VFileEvent {
@NotNull
@Override
public String getPath() {
protected String computePath() {
return myFile.getPath();
}
@@ -101,7 +101,7 @@ public class VFilePropertyChangeEvent extends VFileEvent {
@NotNull
@Override
public String getPath() {
protected String computePath() {
return myFile.getPath();
}