From fcde9ad60eb8bcf85e0f29ca37d4a07dd31422a2 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Sun, 13 Aug 2017 23:46:00 +0300 Subject: [PATCH] Cache the path of VFileEvent to avoid recomputing it for every listener --- .../vfs/newvfs/events/VFileContentChangeEvent.java | 2 +- .../openapi/vfs/newvfs/events/VFileCopyEvent.java | 2 +- .../openapi/vfs/newvfs/events/VFileCreateEvent.java | 2 +- .../openapi/vfs/newvfs/events/VFileDeleteEvent.java | 2 +- .../intellij/openapi/vfs/newvfs/events/VFileEvent.java | 9 ++++++++- .../openapi/vfs/newvfs/events/VFileMoveEvent.java | 2 +- .../vfs/newvfs/events/VFilePropertyChangeEvent.java | 2 +- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileContentChangeEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileContentChangeEvent.java index 999ae951bf97..43db94c0c5b4 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileContentChangeEvent.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileContentChangeEvent.java @@ -61,7 +61,7 @@ public class VFileContentChangeEvent extends VFileEvent { @NotNull @Override - public String getPath() { + protected String computePath() { return myFile.getPath(); } diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCopyEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCopyEvent.java index cd610b5e0e00..b192d532c4b9 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCopyEvent.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCopyEvent.java @@ -59,7 +59,7 @@ public class VFileCopyEvent extends VFileEvent { @NotNull @Override - public String getPath() { + protected String computePath() { return myNewParent.getPath() + "/" + myNewChildName; } diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCreateEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCreateEvent.java index 43cc9fdd5296..0108288e0fa4 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCreateEvent.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCreateEvent.java @@ -63,7 +63,7 @@ public class VFileCreateEvent extends VFileEvent { @NotNull @Override - public String getPath() { + protected String computePath() { return myParent.getPath() + "/" + myChildName; } diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileDeleteEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileDeleteEvent.java index 411534a50336..385fcf319292 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileDeleteEvent.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileDeleteEvent.java @@ -47,7 +47,7 @@ public class VFileDeleteEvent extends VFileEvent { @NotNull @Override - public String getPath() { + protected String computePath() { return myFile.getPath(); } diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileEvent.java index e991a17d24df..78357cd8b956 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileEvent.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileEvent.java @@ -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 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. diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileMoveEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileMoveEvent.java index 012f31d9ee3d..33e8e5a1eb53 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileMoveEvent.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileMoveEvent.java @@ -59,7 +59,7 @@ public class VFileMoveEvent extends VFileEvent { @NotNull @Override - public String getPath() { + protected String computePath() { return myFile.getPath(); } diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFilePropertyChangeEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFilePropertyChangeEvent.java index 0fe15d89eb06..00d8af54ed78 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFilePropertyChangeEvent.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFilePropertyChangeEvent.java @@ -101,7 +101,7 @@ public class VFilePropertyChangeEvent extends VFileEvent { @NotNull @Override - public String getPath() { + protected String computePath() { return myFile.getPath(); }