mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 06:05:01 +07:00
cleanup
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
package com.intellij.openapi.vfs;
|
||||
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.testFramework.IdeaTestCase;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -10,33 +9,28 @@ import java.io.IOException;
|
||||
public class GetPathPerformanceTest extends IdeaTestCase {
|
||||
public void testGetPath() throws IOException {
|
||||
File dir = createTempDirectory();
|
||||
try {
|
||||
File subdir1 = new File(dir, "1");
|
||||
File subdir2 = new File(dir, "2");
|
||||
subdir1.mkdir();
|
||||
subdir2.mkdir();
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
new File(subdir1, "" + i).createNewFile();
|
||||
new File(subdir2, "" + i).createNewFile();
|
||||
}
|
||||
VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(dir.getPath().replace(File.separatorChar, '/'));
|
||||
assertNotNull(file);
|
||||
File subdir1 = new File(dir, "1");
|
||||
File subdir2 = new File(dir, "2");
|
||||
subdir1.mkdir();
|
||||
subdir2.mkdir();
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
new File(subdir1, "" + i).createNewFile();
|
||||
new File(subdir2, "" + i).createNewFile();
|
||||
}
|
||||
VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(dir.getPath().replace(File.separatorChar, '/'));
|
||||
assertNotNull(file);
|
||||
|
||||
final VirtualFile[] children = file.getChildren();
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for( int i = 0; i < 1000000; ++i ) {
|
||||
for( VirtualFile child: children) {
|
||||
child.getPath();
|
||||
}
|
||||
final VirtualFile[] children = file.getChildren();
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for( int i = 0; i < 1000000; ++i ) {
|
||||
for( VirtualFile child: children) {
|
||||
child.getPath();
|
||||
}
|
||||
}
|
||||
};
|
||||
IdeaTestUtil.assertTiming("Performance failed", 3000, runnable);
|
||||
}
|
||||
finally {
|
||||
FileUtil.delete(dir);
|
||||
}
|
||||
}
|
||||
};
|
||||
PlatformTestUtil.assertTiming("Performance failed", 3000, runnable);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-6
@@ -35,6 +35,7 @@ import com.intellij.util.containers.FactoryMap;
|
||||
import com.intellij.util.containers.IntArrayList;
|
||||
import com.intellij.util.text.MergingCharSequence;
|
||||
import gnu.trove.TIntIntHashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
@@ -349,8 +350,8 @@ public class LayeredLexerEditorHighlighter extends LexerEditorHighlighter {
|
||||
doc.replaceString(start, end, tokenText);
|
||||
|
||||
final int newEnd = start + tokenText.length();
|
||||
if (oldMapping.range.getStartOffset() != start ||
|
||||
oldMapping.range.getEndOffset() != newEnd) {
|
||||
if (oldMapping.range.getStartOffset() != start || oldMapping.range.getEndOffset() != newEnd) {
|
||||
assert oldMapping.range.getDocument() == doc;
|
||||
oldMapping.range.dispose();
|
||||
oldMapping.range = doc.createRangeMarker(start, newEnd);
|
||||
}
|
||||
@@ -392,6 +393,7 @@ public class LayeredLexerEditorHighlighter extends LexerEditorHighlighter {
|
||||
if (rangeMarker.isValid()) {
|
||||
final int start = rangeMarker.getStartOffset();
|
||||
final int end = rangeMarker.getEndOffset();
|
||||
assert doc == rangeMarker.getDocument();
|
||||
doc.deleteString(start - mySeparator.length(), end);
|
||||
rangeMarker.dispose();
|
||||
}
|
||||
@@ -399,14 +401,15 @@ public class LayeredLexerEditorHighlighter extends LexerEditorHighlighter {
|
||||
}
|
||||
|
||||
private static class MappedRange {
|
||||
RangeMarker range;
|
||||
final Mapper mapper;
|
||||
final IElementType outerToken;
|
||||
private RangeMarker range;
|
||||
private final Mapper mapper;
|
||||
private final IElementType outerToken;
|
||||
|
||||
MappedRange(final Mapper mapper, final RangeMarker range, final IElementType outerToken) {
|
||||
MappedRange(@NotNull Mapper mapper, @NotNull RangeMarker range, @NotNull IElementType outerToken) {
|
||||
this.mapper = mapper;
|
||||
this.range = range;
|
||||
this.outerToken = outerToken;
|
||||
assert mapper.doc == range.getDocument();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-10
@@ -207,15 +207,13 @@ public class ExpectedHighlightingData {
|
||||
int pos = 0;
|
||||
final Ref<Integer> textOffset = Ref.create(0);
|
||||
while (matcher.find(pos)) {
|
||||
textOffset.set(textOffset.get() + (matcher.start() - pos));
|
||||
textOffset.set(textOffset.get() + matcher.start() - pos);
|
||||
pos = extractExpectedHighlight(matcher, text, document, textOffset);
|
||||
}
|
||||
}
|
||||
|
||||
private int extractExpectedHighlight(final Matcher matcher, final String text, final Document document, final Ref<Integer> textOffset) {
|
||||
final int toContinueFrom;
|
||||
|
||||
document.deleteString(textOffset.get(), textOffset.get() + (matcher.end() - matcher.start()));
|
||||
document.deleteString(textOffset.get(), textOffset.get() + matcher.end() - matcher.start());
|
||||
|
||||
int groupIdx = 1;
|
||||
final String marker = matcher.group(groupIdx++);
|
||||
@@ -256,6 +254,7 @@ public class ExpectedHighlightingData {
|
||||
}
|
||||
|
||||
final int rangeStart = textOffset.get();
|
||||
final int toContinueFrom;
|
||||
if (closed) {
|
||||
toContinueFrom = matcher.end();
|
||||
}
|
||||
@@ -264,18 +263,18 @@ public class ExpectedHighlightingData {
|
||||
final Matcher closingTagMatcher = Pattern.compile("</" + marker + ">").matcher(text);
|
||||
while (true) {
|
||||
if (!closingTagMatcher.find(pos)) {
|
||||
LOG.assertTrue(closingTagMatcher.matches(), "Cannot find closing </" + marker + ">");
|
||||
LOG.error("Cannot find closing </" + marker + "> in position " + pos);
|
||||
}
|
||||
|
||||
final int nextTagStart = matcher.find(pos) ? matcher.start() : text.length();
|
||||
if (closingTagMatcher.start() < nextTagStart) {
|
||||
textOffset.set(textOffset.get() + (closingTagMatcher.start() - pos));
|
||||
document.deleteString(textOffset.get(), textOffset.get() + (closingTagMatcher.end() - closingTagMatcher.start()));
|
||||
textOffset.set(textOffset.get() + closingTagMatcher.start() - pos);
|
||||
document.deleteString(textOffset.get(), textOffset.get() + closingTagMatcher.end() - closingTagMatcher.start());
|
||||
toContinueFrom = closingTagMatcher.end();
|
||||
break;
|
||||
}
|
||||
|
||||
textOffset.set(textOffset.get() + (nextTagStart - pos));
|
||||
textOffset.set(textOffset.get() + nextTagStart - pos);
|
||||
pos = extractExpectedHighlight(matcher, text, document, textOffset);
|
||||
}
|
||||
}
|
||||
@@ -346,7 +345,7 @@ public class ExpectedHighlightingData {
|
||||
}
|
||||
}
|
||||
|
||||
if (failMessage.length() > 0) Assert.assertTrue(failMessage, false);
|
||||
if (failMessage.length() > 0) Assert.fail(failMessage);
|
||||
}
|
||||
|
||||
private static boolean containsLineMarker(LineMarkerInfo info, Collection<LineMarkerInfo> where) {
|
||||
@@ -453,7 +452,7 @@ public class ExpectedHighlightingData {
|
||||
info.endOffset >= prev.endOffset);
|
||||
|
||||
int offset = prevSeverity.length()*2 + 14 + (prev.description != null ? prev.description.length() : 4) + // open and closing tags
|
||||
(prev.endOffset - prev.startOffset) + (info.endOffset - prev.endOffset);
|
||||
prev.endOffset - prev.startOffset + info.endOffset - prev.endOffset;
|
||||
sb.insert(offset, "</" + severity + ">");
|
||||
sb.insert(0, text.substring(info.startOffset, prev.startOffset));
|
||||
sb.insert(0, "<" + severity + " descr=\"" + info.description + "\">");
|
||||
|
||||
Reference in New Issue
Block a user