Analyze huge set of sentences for word presence I have a huge file (1Gb) with English sentences and I need to filter only those containing the Alice word.
Actual tests could be more complex, e.g. matching a verb by its wordforms (go, goes, gone, went, going).
To solve the task I have designed a method, which feeds English word as it is ready to a consumer and if test returns back positive the method returns immediately.
I have improved performance twice in comparison with storing words in a list first and matching them afterwards. Still I have the following benchmarks:

read:  1.6s / 100MB;
process: 1.5s / 100MB.

Could this code be improved further:
import java.util.function.Function;

public class ExtractEnglishWordsAndTest {
    public static boolean extractEnglishWordsAndTest(String text, Function&lt;String, Boolean&gt; consumer) {
        if (text == null || text.isEmpty()) {
            return false;
        }

        char[] buf = new char[text.length()];
        int bufIndex = -1;

        boolean isEnglishPiece = isEnglishLetterOrHyphen(text.charAt(0));

        for (char ch : text.toCharArray()) {
            boolean isEnglishLetter = isEnglishLetterOrHyphen(ch);

            if (isEnglishPiece &amp;&amp; !isEnglishLetter || !isEnglishPiece &amp;&amp; isEnglishLetter) {
                if (isEnglishPiece) {
                    if (consumer.apply(new String(buf, 0, bufIndex + 1))) {
                        return true;
                    }
                }

                isEnglishPiece = !isEnglishPiece;

                bufIndex = -1;
            }

            bufIndex++;
            buf[bufIndex] = ch;
        }

        if (isEnglishPiece) {
            if (consumer.apply(new String(buf, 0, bufIndex + 1))) {
                return true;
            }
        }

        return false;
    }

    public static boolean isEnglishLetterOrHyphen(char ch) {
        return ch &gt;= 'a' &amp;&amp; ch &lt;= 'z' || ch &gt;= 'A' &amp;&amp; ch &lt;= 'Z' || ch == '-';
    }

    public static void main(String[] args) {
        // could be used for just splitting
        ExtractEnglishWordsAndTest.extractEnglishWordsAndTest(&quot;Some key-phrases that may hint to you &quot; +
                &quot;that the question is better suited for Code-Review &quot; +
                &quot;are like the following:&quot;, (word) -&gt; {
            System.out.print(word + &quot; &quot;);
            return false;
        });

        System.out.println();

        System.out.println(&quot;test: &quot; + ExtractEnglishWordsAndTest.extractEnglishWordsAndTest(&quot;In another moment down went Alice after it, &quot; +
                &quot;never once considering how in the world &quot; +
                &quot;she was to get out again.&quot;, (word) -&gt; word.equals(&quot;Alice&quot;)));

        System.out.println(&quot;test: &quot; + ExtractEnglishWordsAndTest.extractEnglishWordsAndTest(&quot;Presently she began again.&quot;,
                (word) -&gt; word.equals(&quot;Alice&quot;)));
    }
}

Output:

Some key-phrases that may hint to you that the question is better
suited for Code-Review are like the following
test: true
test: false
The logic of word extraction seems convoluted. Consider two loops instead, along the lines of

    int text_length = text.length();
    int i = 0;
    while (true) {
        while ((i &lt; text_length) &amp;&amp; !isEnglishLetterOrHyphen(text.charAt(i))) {
            i++;
        }

        int wordStart = i;
        while ((i &lt; text_length) &amp;&amp; isEnglishLetterOrHyphen(text.charAt(i))) {
            i++;
        }

        if (consumer.apply(text.substring(wordStart, i))) {
            return true;
        }
    }


BTW,

    isEnglishPiece &amp;&amp; !isEnglishLetter || !isEnglishPiece &amp;&amp; isEnglishLetter


is a long (and unclear) way to say

    isEnglishPiece != isEnglishLetter