diff_commonSuffix method
Determine the common suffix of two strings
text1
is the first string.
text2
is the second string.
Returns the number of characters common to the end of each string.
Implementation
int diff_commonSuffix(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 text1_length = text1.length;
final text2_length = text2.length;
final n = min(text1_length, text2_length);
for (int i = 1; i <= n; i++) {
if (text1[text1_length - i] != text2[text2_length - i]) {
return i - 1;
}
}
return n;
}