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

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: rebased Created 7 years, 4 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_runner.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..888f8cfc7a8bf9139289f2863679fccb60b9d077 100644
--- a/tools/testing/dart/utils.dart
+++ b/tools/testing/dart/utils.dart
@@ -64,6 +64,55 @@ 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++) {
+ bool found = true;
+ for (int j = 0; j < pattern.length; j++) {
+ if (data[i + j] != pattern[j]) {
+ found = false;
+ break;
+ }
+ }
+ if (found) {
+ return i;
+ }
+ }
+ return -1;
+}
+
List<int> encodeUtf8(String string) {
return utf.encodeUtf8(string);
}
@@ -84,3 +133,22 @@ String escapeCommandLineArgument(String argument) {
return argument;
}
+class HashCodeBuilder {
ahe 2015/05/18 15:48:12 This way of computing a hashCode creates a lot of
kustermann 2015/05/18 18:31:58 Agreed, this is sub-optimal and could be optimized
+ 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_runner.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