Skip to content

Commit 81d015c

Browse files
Alexey Kudravtsevintellij-monorepo-bot
authored andcommitted
optimization: do not recompute document text hashcode on each commit, it can be expensive (may have something to do with RUBY-34515 [regression] Degradation in enter handling)
GitOrigin-RevId: 74c51c0c75a94813a119915f27d4e7997dfb9d48
1 parent b414e00 commit 81d015c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

platform/ide-core-impl/src/com/intellij/psi/impl/DocumentCommitThread.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import org.jetbrains.annotations.NonNls
3333
import org.jetbrains.annotations.TestOnly
3434
import java.lang.ref.Reference
3535
import java.lang.ref.WeakReference
36+
import java.util.Objects
3637
import java.util.concurrent.Callable
3738
import java.util.concurrent.TimeUnit
3839
import java.util.concurrent.TimeoutException
@@ -121,12 +122,10 @@ class DocumentCommitThread : DocumentCommitProcessor, Disposable {
121122
// todo IJPL-339 check if this is correct
122123
for (psiFile in viewProvider.getAllFiles()) {
123124
val oldFileNode = psiFile.getNode()
124-
if (oldFileNode == null) {
125-
throw AssertionError("No node for " + psiFile.javaClass + " in " + psiFile.getViewProvider().javaClass +
126-
" of size " + StringUtil.formatFileSize(document.textLength.toLong()) +
127-
" (is too large = " + SingleRootFileViewProvider
128-
.isTooLargeForIntelligence(viewProvider.getVirtualFile(), document.textLength.toLong()) + ")")
129-
}
125+
?: throw AssertionError("No node for " + psiFile.javaClass + " in " + psiFile.getViewProvider().javaClass +
126+
" of size " + StringUtil.formatFileSize(document.textLength.toLong()) +
127+
" (is too large = " + SingleRootFileViewProvider
128+
.isTooLargeForIntelligence(viewProvider.getVirtualFile(), document.textLength.toLong()) + ")")
130129
val changedPsiRange = ChangedPsiRangeUtil.getChangedPsiRange(
131130
psiFile,
132131
document,
@@ -225,7 +224,10 @@ class DocumentCommitThread : DocumentCommitProcessor, Disposable {
225224
return myDocumentRef.get() == other.myDocumentRef.get() && myProject == other.myProject
226225
}
227226

228-
override fun hashCode(): Int = 31 * myLastCommittedText.hashCode() + myProject.hashCode()
227+
override fun hashCode(): Int {
228+
return 31 * Objects.hashCode(myDocumentRef.get()) + myProject.hashCode()
229+
}
230+
229231
// return null if the document is changed or gced
230232
fun stillValidDocument(): Document? {
231233
val document = myDocumentRef.get()

0 commit comments

Comments
 (0)