Bug 571174 - [performance] improve getLineSeperator()
Old implementation did read files byte by byte.
This is a hot spot in junit test of JDT.
Bug: 571174
Change-Id: Ib08f643c38c51e01c5838743190ca54f591545b1
Signed-off-by: jkubitz <jkubitz-eclipse@gmx.de>
diff --git a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/utils/FileUtil.java b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/utils/FileUtil.java
index bf506e4..9b3d44b 100644
--- a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/utils/FileUtil.java
+++ b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/utils/FileUtil.java
@@ -287,7 +287,9 @@
public static String getLineSeparator(IFile file) {
if (file.exists()) {
try (
- InputStream input = file.getContents()
+ // for performance reasons the buffer size should
+ // reflect the average length of the first Line:
+ InputStream input = new BufferedInputStream(file.getContents(), 128);
) {
int c = input.read();
while (c != -1 && c != '\r' && c != '\n')