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

Side by Side Diff: runtime/lib/byte_array.dart

Issue 9839071: Use named constants for the mask values used to narrow byte array values. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 interface ByteArray extends List default _InternalByteArray { 5 interface ByteArray extends List default _InternalByteArray {
6 ByteArray(int length); 6 ByteArray(int length);
7 7
8 int get length(); 8 int get length();
9 9
10 int getInt8(int byteOffset); 10 int getInt8(int byteOffset);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 157 }
158 158
159 List getRange(int start, int length) { 159 List getRange(int start, int length) {
160 if (length == 0) return []; 160 if (length == 0) return [];
161 Arrays.rangeCheck(this, start, length); 161 Arrays.rangeCheck(this, start, length);
162 ByteArray list = new ByteArray(length); 162 ByteArray list = new ByteArray(length);
163 list._setRange(0, length, this, start); 163 list._setRange(0, length, this, start);
164 return list; 164 return list;
165 } 165 }
166 166
167 // Implementation
167 168
168 // Implementation 169 static final int _UINT8_MAX = (1 << 8) - 1;
170 static final int _UINT16_MAX = (1 << 16) - 1;
171 static final int _UINT32_MAX = (1 << 32) - 1;
172 static final int _UINT64_MAX = (1 << 64) - 1;
169 173
170 int _toInt(int value, int mask) { 174 int _toInt(int value, int mask) {
171 int result = value & mask; 175 int result = value & mask;
172 return result > (mask >> 1) ? (result - mask) : result; 176 return result > (mask >> 1) ? (result - mask) : result;
173 } 177 }
174 178
175 int _toInt8(int value) { 179 int _toInt8(int value) {
176 return _toInt(value, (1 << 8) - 1); // TODO(cshapiro): use a named value 180 return _toInt(value, _UINT8_MAX);
177 } 181 }
178 182
179 int _toUint8(int value) { 183 int _toUint8(int value) {
180 return value & ((1 << 8) - 1); // TODO(cshapiro): use a named value 184 return value & _UINT8_MAX;
181 } 185 }
182 186
183 int _toInt16(int value) { 187 int _toInt16(int value) {
184 return _toInt(value, (1 << 16) - 1); // TODO(cshapiro): use a named value 188 return _toInt(value, _UINT16_MAX);
185 } 189 }
186 190
187 int _toUint16(int value) { 191 int _toUint16(int value) {
188 return value & ((1 << 16) - 1); // TODO(cshapiro): use a named value 192 return value & _UINT16_MAX;
189 } 193 }
190 194
191 int _toInt32(int value) { 195 int _toInt32(int value) {
192 return _toInt(value, (1 << 32) - 1); // TODO(cshapiro): use a named value 196 return _toInt(value, _UINT32_MAX);
193 } 197 }
194 198
195 int _toUint32(int value) { 199 int _toUint32(int value) {
196 return value & ((1 << 32) - 1); // TODO(cshapiro): use a named value 200 return value & _UINT32_MAX;
197 } 201 }
198 202
199 int _toInt64(int value) { 203 int _toInt64(int value) {
200 return _toInt(value, (1 << 64) - 1); // TODO(cshapiro): use a named value 204 return _toInt(value, _UINT64_MAX);
201 } 205 }
202 206
203 int _toUint64(int value) { 207 int _toUint64(int value) {
204 return value & ((1 << 64) - 1); // TODO(cshapiro): use a named value 208 return value & _UINT64_MAX;
205 } 209 }
206 210
207 int _length() native "ByteArray_getLength"; 211 int _length() native "ByteArray_getLength";
208 212
209 void _setRange(int start, int length, ByteArray from, int startFrom) 213 void _setRange(int start, int length, ByteArray from, int startFrom)
210 native "ByteArray_setRange"; 214 native "ByteArray_setRange";
211 } 215 }
212 216
213 217
214 class _ByteArrayIterator implements Iterator { 218 class _ByteArrayIterator implements Iterator {
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 548
545 void _setFloat32(int byteOffset, double value) 549 void _setFloat32(int byteOffset, double value)
546 native "ExternalByteArray_setFloat32"; 550 native "ExternalByteArray_setFloat32";
547 551
548 double _getFloat64(int byteOffset) 552 double _getFloat64(int byteOffset)
549 native "ExternalByteArray_getFloat64"; 553 native "ExternalByteArray_getFloat64";
550 554
551 void _setFloat64(int byteOffset, double value) 555 void _setFloat64(int byteOffset, double value)
552 native "ExternalByteArray_setFloat64"; 556 native "ExternalByteArray_setFloat64";
553 } 557 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698