diff_commonPrefix method

int diff_commonPrefix(
  1. String text1,
  2. String text2
)

Determine the common prefix of two strings text1 is the first string. text2 is the second string. Returns the number of characters common to the start of each string.

Implementation

int diff_commonPrefix(String text1, String text2) {
  // TODO: Once Dart's performance stabilizes, determine if linear or binary
  // search is better.
  // Performance analysis: https://neil.fraser.name/news/2007/10/09/
  final n = min(text1.length, text2.length);
  for (int i = 0; i < n; i++) {
    if (text1[i] != text2[i]) {
      return i;
    }
  }
  return n;
}