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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library utils; 5 library utils;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:utf' as utf; 9 import 'dart:utf' as utf;
10 10
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 if (_sink != null) { 57 if (_sink != null) {
58 _sink.writeln(msg); 58 _sink.writeln(msg);
59 } else { 59 } else {
60 print(msg); 60 print(msg);
61 } 61 }
62 } 62 }
63 63
64 static String get _datetime => "${new DateTime.now()}"; 64 static String get _datetime => "${new DateTime.now()}";
65 } 65 }
66 66
67
68 /**
69 * [areByteArraysEqual] compares a range of bytes from [buffer1] with a
70 * range of bytes from [buffer2].
71 *
72 * Returns [true] if the [count] bytes in [buffer1] (starting at
73 * [offset1]) match the [count] bytes in [buffer2] (starting at
74 * [offset2]).
75 * Otherwise [false] is returned.
76 */
77 bool areByteArraysEqual(List<int> buffer1, int offset1,
78 List<int> buffer2, int offset2,
79 int count) {
80 if ((offset1 + count) > buffer1.length ||
81 (offset2 + count) > buffer2.length) {
82 return false;
83 }
84
85 for (var i = 0; i < count; i++) {
86 if (buffer1[offset1 + i] != buffer2[offset2 + i]) {
87 return false;
88 }
89 }
90 return true;
91 }
92
93 /**
94 * [findBytes] searches for [pattern] in [data] beginning at [startPos].
95 *
96 * Returns [true] if [pattern] was found in [data].
97 * Otherwise [false] is returned.
98 */
99 int findBytes(List<int> data, List<int> pattern, [int startPos=0]) {
100 // TODO(kustermann): Use one of the fast string-matching algorithms!
101 for (int i = startPos; i < (data.length - pattern.length); i++) {
102 bool found = true;
103 for (int j = 0; j < pattern.length; j++) {
104 if (data[i + j] != pattern[j]) {
105 found = false;
106 break;
107 }
108 }
109 if (found) {
110 return i;
111 }
112 }
113 return -1;
114 }
115
67 List<int> encodeUtf8(String string) { 116 List<int> encodeUtf8(String string) {
68 return utf.encodeUtf8(string); 117 return utf.encodeUtf8(string);
69 } 118 }
70 119
71 // TODO(kustermann,ricow): As soon we have a debug log we should log 120 // TODO(kustermann,ricow): As soon we have a debug log we should log
72 // invalid utf8-encoded input to the log. 121 // invalid utf8-encoded input to the log.
73 // Currently invalid bytes will be replaced by a replacement character. 122 // Currently invalid bytes will be replaced by a replacement character.
74 String decodeUtf8(List<int> bytes) { 123 String decodeUtf8(List<int> bytes) {
75 return utf.decodeUtf8(bytes); 124 return utf.decodeUtf8(bytes);
76 } 125 }
77 126
78 // This function is pretty stupid and only puts quotes around an argument if 127 // This function is pretty stupid and only puts quotes around an argument if
79 // it the argument contains a space. 128 // it the argument contains a space.
80 String escapeCommandLineArgument(String argument) { 129 String escapeCommandLineArgument(String argument) {
81 if (argument.contains(' ')) { 130 if (argument.contains(' ')) {
82 return '"$argument"'; 131 return '"$argument"';
83 } 132 }
84 return argument; 133 return argument;
85 } 134 }
86 135
136 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
137 int _value = 0;
138
139 void add(Object object) {
140 _value = ((_value * 31) ^ object.hashCode) & 0x3FFFFFFF;
141 }
142
143 int get value => _value;
144 }
145
146 class UniqueObject {
147 static int _nextId = 1;
148 final int _hashCode;
149
150 int get hashCode => _hashCode;
151 operator==(other) => other is UniqueObject && _hashCode == other._hashCode;
152
153 UniqueObject() : _hashCode = ++_nextId;
154 }
OLDNEW
« 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