diff options
author | George Fraser <george@fivetran.com> | 2018-12-29 12:01:50 -0800 |
---|---|---|
committer | George Fraser <george@fivetran.com> | 2018-12-29 12:01:50 -0800 |
commit | 0ecebc3b3a64e814beced3e71ebff00940796055 (patch) | |
tree | 7aeb6bc1cecdde4cbb8b62b628c4bc1914eb9ffc | |
parent | f463bee9f5ac5da849c522970f78e0756663516f (diff) | |
download | java-language-server-0ecebc3b3a64e814beced3e71ebff00940796055.zip |
Try readAllBytes
-rw-r--r-- | src/main/java/org/javacs/Parser.java | 26 | ||||
-rw-r--r-- | src/main/java/org/javacs/StringSearch.java | 19 |
2 files changed, 26 insertions, 19 deletions
diff --git a/src/main/java/org/javacs/Parser.java b/src/main/java/org/javacs/Parser.java index 05d8ab3..5352bc7 100644 --- a/src/main/java/org/javacs/Parser.java +++ b/src/main/java/org/javacs/Parser.java @@ -5,7 +5,6 @@ import com.sun.source.util.*; import java.io.File; import java.io.IOException; import java.net.URI; -import java.nio.channels.FileChannel; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; @@ -113,12 +112,29 @@ class Parser { } } - // TODO try working on inputstream rather than lines + /* + FileChannel.open(...).map(...) + + Benchmark Mode Cnt Score Error Units + StringSearchBenchmark.boyerMooreLarge thrpt 3 15517.606 ± 4807.393 ops/s + StringSearchBenchmark.boyerMooreSmall thrpt 3 34293.827 ± 58590.197 ops/s + StringSearchBenchmark.regexLarge thrpt 3 1028.404 ± 61.053 ops/s + StringSearchBenchmark.regexSmall thrpt 3 23062.039 ± 4342.233 ops/s + + Files.readAllBytes() + + Benchmark Mode Cnt Score Error Units + StringSearchBenchmark.boyerMooreLarge thrpt 3 18229.198 ± 11873.019 ops/s + StringSearchBenchmark.boyerMooreSmall thrpt 3 45522.137 ± 31464.129 ops/s + StringSearchBenchmark.regexLarge thrpt 3 947.172 ± 228.766 ops/s + StringSearchBenchmark.regexSmall thrpt 3 22039.420 ± 8259.623 ops/s + */ + static boolean containsText(Path java, String query) { var search = new StringSearch(query); - try (var chan = FileChannel.open(java)) { - var buffer = chan.map(FileChannel.MapMode.READ_ONLY, 0, chan.size()); - return search.next(buffer) != -1; + try { + var bytes = Files.readAllBytes(java); + return search.next(bytes) != -1; } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/org/javacs/StringSearch.java b/src/main/java/org/javacs/StringSearch.java index f1b7160..18287f2 100644 --- a/src/main/java/org/javacs/StringSearch.java +++ b/src/main/java/org/javacs/StringSearch.java @@ -1,6 +1,5 @@ package org.javacs; -import java.io.InputStream; import java.nio.ByteBuffer; // Translated from https://golang.org/src/strings/search.go @@ -89,7 +88,11 @@ class StringSearch { } int next(String text) { - return next(ByteBuffer.wrap(text.getBytes())); + return next(text.getBytes()); + } + + int next(byte[] text) { + return next(ByteBuffer.wrap(text)); } int next(ByteBuffer text) { @@ -126,18 +129,6 @@ class StringSearch { return i; } - private static class TextStream { - int offset; - private byte[] head; - private InputStream tail; - - TextStream(InputStream bytes) {} - - void move(int from, int to) {} - - void get(int i) {} - } - private static class Slice { private final byte[] target; private int from, until; |