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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/byte_array.dart
diff --git a/runtime/lib/byte_array.dart b/runtime/lib/byte_array.dart
index 9eac822e486b707c86cba9764d08622250e2e5db..7a807d7aa246406e893ba9b1097b01ff29fa7a36 100644
--- a/runtime/lib/byte_array.dart
+++ b/runtime/lib/byte_array.dart
@@ -164,44 +164,48 @@ class _ByteArrayBase {
return list;
}
-
// Implementation
+ static final int _UINT8_MAX = (1 << 8) - 1;
+ static final int _UINT16_MAX = (1 << 16) - 1;
+ static final int _UINT32_MAX = (1 << 32) - 1;
+ static final int _UINT64_MAX = (1 << 64) - 1;
+
int _toInt(int value, int mask) {
int result = value & mask;
return result > (mask >> 1) ? (result - mask) : result;
}
int _toInt8(int value) {
- return _toInt(value, (1 << 8) - 1); // TODO(cshapiro): use a named value
+ return _toInt(value, _UINT8_MAX);
}
int _toUint8(int value) {
- return value & ((1 << 8) - 1); // TODO(cshapiro): use a named value
+ return value & _UINT8_MAX;
}
int _toInt16(int value) {
- return _toInt(value, (1 << 16) - 1); // TODO(cshapiro): use a named value
+ return _toInt(value, _UINT16_MAX);
}
int _toUint16(int value) {
- return value & ((1 << 16) - 1); // TODO(cshapiro): use a named value
+ return value & _UINT16_MAX;
}
int _toInt32(int value) {
- return _toInt(value, (1 << 32) - 1); // TODO(cshapiro): use a named value
+ return _toInt(value, _UINT32_MAX);
}
int _toUint32(int value) {
- return value & ((1 << 32) - 1); // TODO(cshapiro): use a named value
+ return value & _UINT32_MAX;
}
int _toInt64(int value) {
- return _toInt(value, (1 << 64) - 1); // TODO(cshapiro): use a named value
+ return _toInt(value, _UINT64_MAX);
}
int _toUint64(int value) {
- return value & ((1 << 64) - 1); // TODO(cshapiro): use a named value
+ return value & _UINT64_MAX;
}
int _length() native "ByteArray_getLength";
« 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