the overall effect is that no character of p is compared to any character of the text more than once. the total number of character comparisons is bounded by m, so the total complexity is indeed o(m+log n).