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

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

Issue 9235067: Use ByteArray's native for Socket and File. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 10 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) 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 return Collections.some(this, f); 89 return Collections.some(this, f);
90 } 90 }
91 91
92 // List interface 92 // List interface
93 93
94 int operator[](int index) { 94 int operator[](int index) {
95 return getUint8(index); 95 return getUint8(index);
96 } 96 }
97 97
98 void operator[]=(int index, int value) { 98 void operator[]=(int index, int value) {
99 if (value is! int || !(value >= 0 && value <= 255)) {
cshapiro 2012/01/31 03:04:29 Why not simplify this expression? if ((value is
Anders Johnsen 2012/01/31 03:34:56 Done.
100 throw const IllegalArgumentException(
101 "value is not an integer in byte range");
102 }
99 setUint8(index, value); 103 setUint8(index, value);
100 } 104 }
101 105
102 void set length(int newLength) { 106 void set length(int newLength) {
103 throw const UnsupportedOperationException("Cannot add to a byte array"); 107 throw const UnsupportedOperationException("Cannot add to a byte array");
104 } 108 }
105 109
106 void add(int element) { 110 void add(int element) {
107 throw const UnsupportedOperationException("Cannot add to a byte array"); 111 throw const UnsupportedOperationException("Cannot add to a byte array");
108 } 112 }
(...skipping 25 matching lines...) Expand all
134 138
135 int removeLast() { 139 int removeLast() {
136 throw const UnsupportedOperationException( 140 throw const UnsupportedOperationException(
137 "Cannot remove from a byte array"); 141 "Cannot remove from a byte array");
138 } 142 }
139 143
140 int last() { 144 int last() {
141 return this[length - 1]; 145 return this[length - 1];
142 } 146 }
143 147
148 void setRange(int start, int length, List<int> from, [int startFrom = 0]) {
149 if (length < 0) {
150 throw new IllegalArgumentException("negative length $length");
151 }
152 if (from is ByteArray) {
153 _setRange(from, startFrom, start, length);
154 } else {
155 Arrays.copy(from, startFrom, this, start, length);
156 }
157 }
158
159 List getRange(int start, int length) {
160 if (length == 0) return [];
161 Arrays.rangeCheck(this, start, length);
162 ByteArray list = new ByteArray(length);
163 list._setRange(this, start, 0, length);
164 return list;
165 }
166
167
144 // Implementation 168 // Implementation
145 169
146 int _length() native "ByteArray_getLength"; 170 int _length() native "ByteArray_getLength";
171
172 void _setRange(ByteArray src,
173 int srcStart,
174 int dstStart,
175 int count)
176 native "ByteArray_setRange";
177
147 } 178 }
148 179
149 180
150 class _ByteArrayIterator implements Iterator { 181 class _ByteArrayIterator implements Iterator {
151 _ByteArrayIterator(List byteArray) 182 _ByteArrayIterator(List byteArray)
152 : _byteArray = byteArray, _length = byteArray.length, _pos = 0 { 183 : _byteArray = byteArray, _length = byteArray.length, _pos = 0 {
153 assert(byteArray is ByteArray); 184 assert(byteArray is ByteArray);
154 } 185 }
155 186
156 bool hasNext() { 187 bool hasNext() {
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 511
481 void _setFloat32(int byteOffset, double value) 512 void _setFloat32(int byteOffset, double value)
482 native "ExternalByteArray_setFloat32"; 513 native "ExternalByteArray_setFloat32";
483 514
484 double _getFloat64(int byteOffset) 515 double _getFloat64(int byteOffset)
485 native "ExternalByteArray_getFloat64"; 516 native "ExternalByteArray_getFloat64";
486 517
487 void _setFloat64(int byteOffset, double value) 518 void _setFloat64(int byteOffset, double value)
488 native "ExternalByteArray_setFloat64"; 519 native "ExternalByteArray_setFloat64";
489 } 520 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698