Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Unified Diff: pkg/analysis_server/lib/src/services/correction/diff.dart

Issue 615313004: Use simple prefix/suffix diff in members sorter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/correction/sort_members.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/correction/diff.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/diff.dart b/pkg/analysis_server/lib/src/services/correction/diff.dart
new file mode 100644
index 0000000000000000000000000000000000000000..dcce26eff11d67232ddef99f5060c090a2815aee
--- /dev/null
+++ b/pkg/analysis_server/lib/src/services/correction/diff.dart
@@ -0,0 +1,33 @@
+library diff;
Brian Wilkerson 2014/10/02 13:48:57 missing copyright
+
+import 'dart:math';
+
+
+/**
+ * Return the number of characters common to the start of [a] and [b].
+ */
+int findCommonPrefix(String a, String b) {
Brian Wilkerson 2014/10/02 13:48:57 These seem like they belong in our StringUtilities
+ int n = min(a.length, b.length);
+ for (int i = 0; i < n; i++) {
+ if (a.codeUnitAt(i) != b.codeUnitAt(i)) {
+ return i;
+ }
+ }
+ return n;
+}
+
+
+/**
+ * Return the number of characters common to the end of [a] and [b].
+ */
+int findCommonSuffix(String a, String b) {
+ int a_length = a.length;
+ int b_length = b.length;
+ int n = min(a_length, b_length);
+ for (int i = 1; i <= n; i++) {
+ if (a.codeUnitAt(a_length - i) != b.codeUnitAt(b_length - i)) {
+ return i - 1;
+ }
+ }
+ return n;
+}
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/correction/sort_members.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698