Skip to content

Commit eb07e69

Browse files
committed
Fix #2118 : limit CtagsReader lookahead for pathologically-long lines
Background: Universal ctags extracts tags from pathologically-long lines but only shows the pattern from the initial part of the line. OpenGrok will now only try to find heuristically the position of tags beyond the initial pattern up to a limit of 2,000 characters. Also, a tiny cache is used to speed sequential tags from the same line.
1 parent b173dbc commit eb07e69

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/org/opensolaris/opengrok/analysis/CtagsReader.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public class CtagsReader {
7676
*/
7777
private static final int MAX_METHOD_LINE_LENGTH = 1030;
7878

79+
private static final int MAX_CUT_LENGTH = 2000;
80+
7981
/**
8082
* E.g. krb5 src/kdc/kdc_authdata.c has a signature for handle_authdata()
8183
* split across twelve lines, so use double that number.
@@ -90,6 +92,8 @@ public class CtagsReader {
9092
private Supplier<SourceSplitter> splitterSupplier;
9193
private boolean triedSplitterSupplier;
9294
private SourceSplitter splitter;
95+
private long cutCacheKey;
96+
private String cutCacheValue;
9397

9498
private int tabSize;
9599

@@ -760,12 +764,23 @@ private String trySplitterCut(int lineOffset, int maxLines) {
760764
}
761765
}
762766

767+
long newCutCacheKey = ((long)lineOffset << 32) | maxLines;
768+
if (cutCacheKey == newCutCacheKey) {
769+
return cutCacheValue;
770+
}
771+
763772
StringBuilder cutbld = new StringBuilder();
764773
for (int i = lineOffset; i < lineOffset + maxLines &&
765-
i < splitter.count(); ++i) {
774+
i < splitter.count() && cutbld.length() < MAX_CUT_LENGTH;
775+
++i) {
766776
cutbld.append(splitter.getLine(i));
767777
}
768-
return cutbld.toString();
778+
if (cutbld.length() > MAX_CUT_LENGTH) {
779+
cutbld.setLength(MAX_CUT_LENGTH);
780+
}
781+
cutCacheValue = cutbld.toString();
782+
cutCacheKey = newCutCacheKey;
783+
return cutCacheValue;
769784
}
770785

771786
/**

0 commit comments

Comments
 (0)