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

Unified Diff: tools/testing/dart/utils.dart

Issue 21001003: test.py: First step towards support of caching dart2js compilations across runtimes (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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
« tools/testing/dart/test_suite.dart ('K') | « tools/testing/dart/test_suite.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/testing/dart/utils.dart
diff --git a/tools/testing/dart/utils.dart b/tools/testing/dart/utils.dart
index 3ddf330b75bf8e91b047e74abf5d4fa9c9310037..908013ae71235f91c0af588a861d10c59e872a26 100644
--- a/tools/testing/dart/utils.dart
+++ b/tools/testing/dart/utils.dart
@@ -64,6 +64,54 @@ class DebugLogger {
static String get _datetime => "${new DateTime.now()}";
}
+
+/**
+ * [areByteArraysEqual] compares a range of bytes from [buffer1] with a
+ * range of bytes from [buffer2].
+ *
+ * Returns [true] if the [count] bytes in [buffer1] (starting at
+ * [offset1]) match the [count] bytes in [buffer2] (starting at
+ * [offset2]).
+ * Otherwise [false] is returned.
+ */
+bool areByteArraysEqual(List<int> buffer1, int offset1,
+ List<int> buffer2, int offset2,
+ int count) {
+ if ((offset1 + count) > buffer1.length ||
+ (offset2 + count) > buffer2.length) {
+ return false;
+ }
+
+ for (var i = 0; i < count; i++) {
+ if (buffer1[offset1 + i] != buffer2[offset2 + i]) {
+ return false;
+ }
+ }
+ return true;
+}
+
+/**
+ * [findBytes] searches for [pattern] in [data] beginning at [startPos].
+ *
+ * Returns [true] if [pattern] was found in [data].
+ * Otherwise [false] is returned.
+ */
+int findBytes(List<int> data, List<int> pattern, [int startPos=0]) {
+ // TODO(kustermann): Use one of the fast string-matching algorithms!
+ for (int i=startPos; i < (data.length-pattern.length); i++) {
ricow1 2013/07/30 09:30:11 space around = I would remove parenthesis around d
kustermann 2013/07/31 15:53:54 Done. Kept the parenthesis (it's not that obvious
ricow1 2013/08/01 13:26:21 OH, as discussed offline I though length-pattern w
+ bool found = true;
+ for (int j=0; j<pattern.length; j++) {
ricow1 2013/07/30 09:30:11 space around = and <
kustermann 2013/07/31 15:53:54 Done.
+ if (data[i+j] != pattern[j]) {
+ found = false;
ricow1 2013/07/30 09:30:11 break here?
kustermann 2013/07/31 15:53:54 Done.
+ }
+ }
+ if (found) {
+ return i;
+ }
+ }
+ return -1;
+}
+
List<int> encodeUtf8(String string) {
return utf.encodeUtf8(string);
}
@@ -84,3 +132,22 @@ String escapeCommandLineArgument(String argument) {
return argument;
}
+class HashCodeBuilder {
+ int _value = 0;
+
+ void add(Object object) {
+ _value = ((_value * 31) ^ object.hashCode) & 0x3FFFFFFF;
+ }
+
+ int get value => _value;
+}
+
+class UniqueObject {
+ static int _nextId = 1;
+ final int _hashCode;
+
+ int get hashCode => _hashCode;
+ operator==(other) => other is UniqueObject && _hashCode == other._hashCode;
+
+ UniqueObject() : _hashCode = ++_nextId;
+}
« tools/testing/dart/test_suite.dart ('K') | « tools/testing/dart/test_suite.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698