In a nutshell
This method compiles the pattern into a DFA — a deterministic finite automaton, a little machine with one state for every amount of the pattern matched so far (0 characters, 1, … up to the full pattern). A precomputed table says, for each state and each possible next character, which state to move to. Searching is then just reading the text once, following one transition per character; reaching the final 'accept' state means the pattern was found. Building the table costs O(m × alphabet size), but the scan itself is a single linear pass.