From 03895edada607949d2a8d7858a5fab80383121d0 Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Tue, 18 Apr 2017 13:55:55 +0200 Subject: [PATCH] potential undo freezes: compact map to avoid iteration over empty buckets --- .../command/impl/UndoRedoStacksHolder.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedoStacksHolder.java b/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedoStacksHolder.java index 46106ad4b5af..9cb15bfabee1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedoStacksHolder.java +++ b/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedoStacksHolder.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,8 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.UserDataHolder; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.containers.HashMap; import com.intellij.util.containers.WeakList; +import gnu.trove.THashMap; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.TestOnly; @@ -37,7 +37,7 @@ class UndoRedoStacksHolder { private final LinkedList myGlobalStack = new LinkedList<>(); // strongly reference local files for which we can undo file removal // document without files and nonlocal files are stored without strong reference - private final Map> myDocumentStacks = new HashMap<>(); + private final THashMap> myDocumentStacks = new THashMap<>(); private final List myDocumentsWithStacks = new WeakList<>(); private final List myNonlocalVirtualFilesWithStacks = new WeakList<>(); @@ -170,14 +170,8 @@ class UndoRedoStacksHolder { } } - Set stacksToDrop = new THashSet<>(); - for (Map.Entry> each : myDocumentStacks.entrySet()) { - if (each.getValue().isEmpty()) stacksToDrop.add(each.getKey()); - } - for (DocumentReference each : stacksToDrop) { - myDocumentStacks.remove(each); - } - + myDocumentStacks.entrySet().removeIf(each -> each.getValue().isEmpty()); + myDocumentStacks.compact(); // make sure the following entrySet iteration will not go over empty buckets. cleanWeaklyTrackedEmptyStacks(myDocumentsWithStacks); cleanWeaklyTrackedEmptyStacks(myNonlocalVirtualFilesWithStacks); -- 2.32.0