| OLD | NEW |
| 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 /** | 5 patch class Int8List { |
| 6 * A random-access sequence of bytes that also provides random access to | 6 /* patch */ factory Int8List(int length) { |
| 7 * the fixed-width integers and floating point numbers represented by | |
| 8 * those bytes. Byte arrays may be used to pack and unpack data from | |
| 9 * external sources (such as networks or files systems), and to process | |
| 10 * large quantities of numerical data more efficiently than would be possible | |
| 11 * with ordinary [List] implementations. Byte arrays can save space, by | |
| 12 * eliminating the need for object headers, and time, by eliminating the | |
| 13 * need for data copies. Finally, Byte arrays may be used to intentionally | |
| 14 * reinterpret the bytes representing one arithmetic type as another. | |
| 15 * For example this code fragment determine what 64-bit signed integer | |
| 16 * is represented by the bytes of a 64-bit floating point number: | |
| 17 * | |
| 18 * var ba = new ByteArray(8); | |
| 19 * ba.setFloat64(0, 3.14159265358979323846); | |
| 20 * int huh = ba.getInt64(0); | |
| 21 */ | |
| 22 interface ByteArray { | |
| 23 /** | |
| 24 * Returns the length of this byte array, in bytes. | |
| 25 */ | |
| 26 int lengthInBytes(); | |
| 27 | |
| 28 /** | |
| 29 * Returns a [ByteArray] _view_ of a portion of this byte array. | |
| 30 * The returned byte array consists of [length] bytes starting | |
| 31 * at position [start] in this byte array. The returned byte array | |
| 32 * is backed by the same data as this byte array. In other words, | |
| 33 * changes to the returned byte array are visible in this byte array | |
| 34 * and vice-versa. | |
| 35 * | |
| 36 * Throws [IndexOutOfRangeException] if [start] is negative, or if | |
| 37 * `start + length` is greater than the length of this byte array. | |
| 38 * | |
| 39 * Throws [IllegalArgumentException] if [length] is negative. | |
| 40 */ | |
| 41 ByteArray subByteArray([int start, int length]); | |
| 42 | |
| 43 /** | |
| 44 * Returns the (possibly negative) integer represented by the byte at the | |
| 45 * specified [byteOffset] in this byte array, in two's complement binary | |
| 46 * representation. The return value will be between -128 and 127, inclusive. | |
| 47 * | |
| 48 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or | |
| 49 * greater than or equal to the length of this byte array. | |
| 50 */ | |
| 51 int getInt8(int byteOffset); | |
| 52 | |
| 53 /** | |
| 54 * Sets the byte at the specified [byteOffset] in this byte array to the | |
| 55 * two's complement binary representation of the specified [value], which | |
| 56 * must fit in a single byte. In other words, [value] must be between | |
| 57 * -128 and 127, inclusive. | |
| 58 * | |
| 59 * Returns `byteOffset + 1`, which is the offset of the first byte in the | |
| 60 * array after the byte that was set by this call. This return value can | |
| 61 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. | |
| 62 * | |
| 63 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or | |
| 64 * greater than or equal to the length of this byte array. | |
| 65 * | |
| 66 * Throws [IllegalArgumentException] if [value] is less than -128 or | |
| 67 * greater than 127. | |
| 68 */ | |
| 69 int setInt8(int byteOffset, int value); | |
| 70 | |
| 71 /** | |
| 72 * Returns the positive integer represented by the byte at the specified | |
| 73 * [byteOffset] in this byte array, in unsigned binary form. The | |
| 74 * return value will be between 0 and 255, inclusive. | |
| 75 * | |
| 76 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or | |
| 77 * greater than or equal to the length of this byte array. | |
| 78 */ | |
| 79 int getUint8(int byteOffset); | |
| 80 | |
| 81 /** | |
| 82 * Sets the byte at the specified [byteOffset] in this byte array to the | |
| 83 * unsigned binary representation of the specified [value], which must fit | |
| 84 * in a single byte. in other words, [value] must be between 0 and 255, | |
| 85 * inclusive. | |
| 86 * | |
| 87 * Returns `byteOffset + 1`, which is the offset of the first byte in the | |
| 88 * array after the byte that was set by this call. This return value can | |
| 89 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. | |
| 90 * | |
| 91 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, | |
| 92 * or greater than or equal to the length of this byte array. | |
| 93 * | |
| 94 * Throws [IllegalArgumentException] if [value] is negative or | |
| 95 * greater than 255. | |
| 96 */ | |
| 97 int setUint8(int byteOffset, int value); | |
| 98 | |
| 99 /** | |
| 100 * Returns the (possibly negative) integer represented by the two bytes at | |
| 101 * the specified [byteOffset] in this byte array, in two's complement binary | |
| 102 * form. The return value will be between 2<sup>15</sup> and 2<sup>15 - 1, | |
| 103 * inclusive. | |
| 104 * | |
| 105 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or | |
| 106 * `byteOffset + 2` is greater than the length of this byte array. | |
| 107 */ | |
| 108 int getInt16(int byteOffset); | |
| 109 | |
| 110 /** | |
| 111 * Sets the two bytes starting at the specified [byteOffset] in this | |
| 112 * byte array to the two's complement binary representation of the specified | |
| 113 * [value], which must fit in two bytes. In other words, [value] must lie | |
| 114 * between 2<sup>15</sup> and 2<sup>15 - 1, inclusive. | |
| 115 * | |
| 116 * Returns `byteOffset + 2`, which is the offset of the first byte in the | |
| 117 * array after the last byte that was set by this call. This return value can | |
| 118 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. | |
| 119 * | |
| 120 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or | |
| 121 * `byteOffset + 2` is greater than the length of this byte array. | |
| 122 * | |
| 123 * Throws [IllegalArgumentException] if [value] is less than 2<sup>15</sup> | |
| 124 * or greater than 2<sup>15 - 1. | |
| 125 */ | |
| 126 int setInt16(int byteOffset, int value); | |
| 127 | |
| 128 /** | |
| 129 * Returns the positive integer represented by the two bytes starting | |
| 130 * at the specified [byteOffset] in this byte array, in unsigned binary | |
| 131 * form. The return value will be between 0 and 2<sup>16 - 1, inclusive. | |
| 132 * | |
| 133 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or | |
| 134 * `byteOffset + 2` is greater than the length of this byte array. | |
| 135 */ | |
| 136 int getUint16(int byteOffset); | |
| 137 | |
| 138 /** | |
| 139 * Sets the two bytes starting at the specified [byteOffset] in this byte | |
| 140 * array to the unsigned binary representation of the specified [value], | |
| 141 * which must fit in two bytes. in other words, [value] must be between | |
| 142 * 0 and 2<sup>16 - 1, inclusive. | |
| 143 * | |
| 144 * Returns `byteOffset + 2`, which is the offset of the first byte in the | |
| 145 * array after the last byte that was set by this call. This return value can | |
| 146 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. | |
| 147 * | |
| 148 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or | |
| 149 * `byteOffset + 2` is greater than the length of this byte array. | |
| 150 * | |
| 151 * Throws [IllegalArgumentException] if [value] is negative or | |
| 152 * greater than 2<sup>16 - 1. | |
| 153 */ | |
| 154 int setUint16(int byteOffset, int value); | |
| 155 | |
| 156 /** | |
| 157 * Returns the (possibly negative) integer represented by the four bytes at | |
| 158 * the specified [byteOffset] in this byte array, in two's complement binary | |
| 159 * form. The return value will be between 2<sup>31</sup> and 2<sup>31 - 1, | |
| 160 * inclusive. | |
| 161 * | |
| 162 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or | |
| 163 * `byteOffset + 4` is greater than the length of this byte array. | |
| 164 */ | |
| 165 int getInt32(int byteOffset); | |
| 166 | |
| 167 /** | |
| 168 * Sets the four bytes starting at the specified [byteOffset] in this | |
| 169 * byte array to the two's complement binary representation of the specified | |
| 170 * [value], which must fit in four bytes. In other words, [value] must lie | |
| 171 * between 2<sup>31</sup> and 2<sup>31 - 1, inclusive. | |
| 172 * | |
| 173 * Returns `byteOffset + 4`, which is the offset of the first byte in the | |
| 174 * array after the last byte that was set by this call. This return value can | |
| 175 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. | |
| 176 * | |
| 177 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or | |
| 178 * `byteOffset + 4` is greater than the length of this byte array. | |
| 179 * | |
| 180 * Throws [IllegalArgumentException] if [value] is less than 2<sup>31</sup> | |
| 181 * or greater than 2<sup>31 - 1. | |
| 182 */ | |
| 183 int setInt32(int byteOffset, int value); | |
| 184 | |
| 185 /** | |
| 186 * Returns the positive integer represented by the four bytes starting | |
| 187 * at the specified [byteOffset] in this byte array, in unsigned binary | |
| 188 * form. The return value will be between 0 and 2<sup>32 - 1, inclusive. | |
| 189 * | |
| 190 */ | |
| 191 int getUint32(int byteOffset); | |
| 192 | |
| 193 /** | |
| 194 * Sets the four bytes starting at the specified [byteOffset] in this byte | |
| 195 * array to the unsigned binary representation of the specified [value], | |
| 196 * which must fit in four bytes. in other words, [value] must be between | |
| 197 * 0 and 2<sup>32 - 1, inclusive. | |
| 198 * | |
| 199 * Returns `byteOffset + 4`, which is the offset of the first byte in the | |
| 200 * array after the last byte that was set by this call. This return value can | |
| 201 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. | |
| 202 * | |
| 203 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or | |
| 204 * `byteOffset + 4` is greater than the length of this byte array. | |
| 205 * | |
| 206 * Throws [IllegalArgumentException] if [value] is negative or | |
| 207 * greater than 2<sup>32 - 1. | |
| 208 */ | |
| 209 int setUint32(int byteOffset, int value); | |
| 210 | |
| 211 /** | |
| 212 * Returns the (possibly negative) integer represented by the eight bytes at | |
| 213 * the specified [byteOffset] in this byte array, in two's complement binary | |
| 214 * form. The return value will be between 2<sup>63</sup> and 2<sup>63 - 1, | |
| 215 * inclusive. | |
| 216 * | |
| 217 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or | |
| 218 * `byteOffset + 8` is greater than the length of this byte array. | |
| 219 */ | |
| 220 int getInt64(int byteOffset); | |
| 221 | |
| 222 /** | |
| 223 * Sets the eight bytes starting at the specified [byteOffset] in this | |
| 224 * byte array to the two's complement binary representation of the specified | |
| 225 * [value], which must fit in eight bytes. In other words, [value] must lie | |
| 226 * between 2<sup>63</sup> and 2<sup>63 - 1, inclusive. | |
| 227 * | |
| 228 * Returns `byteOffset + 8`, which is the offset of the first byte in the | |
| 229 * array after the last byte that was set by this call. This return value can | |
| 230 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. | |
| 231 * | |
| 232 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or | |
| 233 * `byteOffset + 8` is greater than the length of this byte array. | |
| 234 * | |
| 235 * Throws [IllegalArgumentException] if [value] is less than 2<sup>63</sup> | |
| 236 * or greater than 2<sup>63 - 1. | |
| 237 */ | |
| 238 int setInt64(int byteOffset, int value); | |
| 239 | |
| 240 /** | |
| 241 * Returns the positive integer represented by the eight bytes starting | |
| 242 * at the specified [byteOffset] in this byte array, in unsigned binary | |
| 243 * form. The return value will be between 0 and 2<sup>64 - 1, inclusive. | |
| 244 * | |
| 245 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or | |
| 246 * `byteOffset + 8` is greater than the length of this byte array. | |
| 247 */ | |
| 248 int getUint64(int byteOffset); | |
| 249 | |
| 250 /** | |
| 251 * Sets the eight bytes starting at the specified [byteOffset] in this byte | |
| 252 * array to the unsigned binary representation of the specified [value], | |
| 253 * which must fit in eight bytes. in other words, [value] must be between | |
| 254 * 0 and 2<sup>64 - 1, inclusive. | |
| 255 * | |
| 256 * Returns `byteOffset + 8`, which is the offset of the first byte in the | |
| 257 * array after the last byte that was set by this call. This return value can | |
| 258 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. | |
| 259 * | |
| 260 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or | |
| 261 * `byteOffset + 8` is greater than the length of this byte array. | |
| 262 * | |
| 263 * Throws [IllegalArgumentException] if [value] is negative or | |
| 264 * greater than 2<sup>64 - 1. | |
| 265 */ | |
| 266 int setUint64(int byteOffset, int value); | |
| 267 | |
| 268 /** | |
| 269 * Returns the floating point number represented by the four bytes at | |
| 270 * the specified [byteOffset] in this byte array, in IEEE 754 | |
| 271 * single-precision binary floating-point format (binary32). | |
| 272 * | |
| 273 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or | |
| 274 * `byteOffset + 4` is greater than the length of this byte array. | |
| 275 */ | |
| 276 double getFloat32(int byteOffset); | |
| 277 | |
| 278 /** | |
| 279 * Sets the four bytes starting at the specified [byteOffset] in this | |
| 280 * byte array to the IEEE 754 single-precision binary floating-point | |
| 281 * (binary32) representation of the specified [value]. | |
| 282 * | |
| 283 * **Note that this method can lose precision.** The input [value] is | |
| 284 * a 64-bit floating point value, which will be converted to 32-bit | |
| 285 * floating point value by IEEE 754 rounding rules before it is stored. | |
| 286 * If [value] cannot be represented exactly as a binary32, it will be | |
| 287 * converted to the nearest binary32 value. If two binary32 values are | |
| 288 * equally close, the one whose least significant bit is zero will be used. | |
| 289 * Note that finite (but large) values can be converted to infinity, and | |
| 290 * small non-zero values can be converted to zero. | |
| 291 * | |
| 292 * Returns `byteOffset + 4`, which is the offset of the first byte in the | |
| 293 * array after the last byte that was set by this call. This return value can | |
| 294 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. | |
| 295 * | |
| 296 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or | |
| 297 * `byteOffset + 4` is greater than the length of this byte array. | |
| 298 */ | |
| 299 int setFloat32(int byteOffset, double value); | |
| 300 | |
| 301 /** | |
| 302 * Returns the floating point number represented by the eight bytes at | |
| 303 * the specified [byteOffset] in this byte array, in IEEE 754 | |
| 304 * double-precision binary floating-point format (binary64). | |
| 305 * | |
| 306 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or | |
| 307 * `byteOffset + 8` is greater than the length of this byte array. | |
| 308 */ | |
| 309 double getFloat64(int byteOffset); | |
| 310 | |
| 311 /** | |
| 312 * Sets the eight bytes starting at the specified [byteOffset] in this | |
| 313 * byte array to the IEEE 754 double-precision binary floating-point | |
| 314 * (binary64) representation of the specified [value]. | |
| 315 * | |
| 316 * Returns `byteOffset + 8`, which is the offset of the first byte in the | |
| 317 * array after the last byte that was set by this call. This return value can | |
| 318 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. | |
| 319 * | |
| 320 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or | |
| 321 * `byteOffset + 8` is greater than the length of this byte array. | |
| 322 */ | |
| 323 int setFloat64(int byteOffset, double value); | |
| 324 } | |
| 325 | |
| 326 /** | |
| 327 * A "mixin" interface that allows a type, typically but not necessarily | |
| 328 * a [List], to be viewed as a [ByteArray]. | |
| 329 */ | |
| 330 interface ByteArrayViewable { | |
| 331 /** | |
| 332 * Returns the number of bytes in the representation of each element in | |
| 333 * this list, or the number bytes in the representation of the entire | |
| 334 * object if it is not a list. | |
| 335 */ | |
| 336 int bytesPerElement(); | |
| 337 | |
| 338 /** | |
| 339 * Returns the length of this view, in bytes. | |
| 340 */ | |
| 341 int lengthInBytes(); | |
| 342 | |
| 343 /** | |
| 344 * Returns the byte array view of this object. This view allows the | |
| 345 * byte representation of the object to be read and written directly. | |
| 346 */ | |
| 347 ByteArray asByteArray([int start, int length]); | |
| 348 } | |
| 349 | |
| 350 | |
| 351 /** | |
| 352 * A fixed-length list of 8-bit signed integers that is viewable as a | |
| 353 * [ByteArray]. For long lists, this implementation will be considerably | |
| 354 * more space- and time-efficient than the default [List] implementation. | |
| 355 */ | |
| 356 interface Int8List extends List<int>, ByteArrayViewable | |
| 357 default _Int8ArrayFactory { | |
| 358 /** | |
| 359 * Creates an [Int8List] of the specified length (in elements), all of | |
| 360 * whose elements are initially zero. | |
| 361 */ | |
| 362 Int8List(int length); | |
| 363 | |
| 364 /** | |
| 365 * Creates an [Int8List] _view_ of the specified region in the specified | |
| 366 * byte [array]. Changes in the [Int8List] will be visible in the byte | |
| 367 * array and vice versa. If the [start] index of the region is not specified, | |
| 368 * it defaults to zero (the first byte in the byte array). If the length is | |
| 369 * not specified, it defaults to null, which indicates that the view extends | |
| 370 * to the end of the byte array. | |
| 371 */ | |
| 372 Int8List.view(ByteArray array, [int start, int length]); | |
| 373 } | |
| 374 | |
| 375 | |
| 376 /** | |
| 377 * A fixed-length list of 8-bit unsigned integers that is viewable as a | |
| 378 * [ByteArray]. For long lists, this implementation will be considerably | |
| 379 * more space- and time-efficient than the default [List] implementation. | |
| 380 */ | |
| 381 interface Uint8List extends List<int>, ByteArrayViewable | |
| 382 default _Uint8ArrayFactory { | |
| 383 /** | |
| 384 * Creates a [Uint8List] of the specified length (in elements), all of | |
| 385 * whose elements are initially zero. | |
| 386 */ | |
| 387 Uint8List(int length); | |
| 388 | |
| 389 /** | |
| 390 * Creates a [Uint8List] _view_ of the specified region in the specified | |
| 391 * byte [array]. Changes in the [Uint8List] will be visible in the byte | |
| 392 * array and vice versa. If the [start] index of the region is not specified, | |
| 393 * it defaults to zero (the first byte in the byte array). If the length is | |
| 394 * not specified, it defaults to null, which indicates that the view extends | |
| 395 * to the end of the byte array. | |
| 396 */ | |
| 397 Uint8List.view(ByteArray array, [int start, int length]); | |
| 398 } | |
| 399 | |
| 400 | |
| 401 /** | |
| 402 * A fixed-length list of 16-bit signed integers that is viewable as a | |
| 403 * [ByteArray]. For long lists, this implementation will be considerably | |
| 404 * more space- and time-efficient than the default [List] implementation. | |
| 405 */ | |
| 406 interface Int16List extends List<int>, ByteArrayViewable | |
| 407 default _Int16ArrayFactory { | |
| 408 /** | |
| 409 * Creates an [Int16List] of the specified length (in elements), all of | |
| 410 * whose elements are initially zero. | |
| 411 */ | |
| 412 Int16List(int length); | |
| 413 | |
| 414 /** | |
| 415 * Creates an [Int16List] _view_ of the specified region in the specified | |
| 416 * byte [array]. Changes in the [Int16List] will be visible in the byte | |
| 417 * array and vice versa. If the [start] index of the region is not specified, | |
| 418 * it defaults to zero (the first byte in the byte array). If the length is | |
| 419 * not specified, it defaults to null, which indicates that the view extends | |
| 420 * to the end of the byte array. | |
| 421 * | |
| 422 * Throws [IllegalArgumentException] if the length of the specified region | |
| 423 * is not divisible by 2 (the size of an "int16" in bytes), or if the | |
| 424 * [start] of the region is not divisible by 2. If, however, [array] | |
| 425 * is a view of another byte array, this constructor will throw | |
| 426 * [IllegalArgumentException] if the implicit starting position in the | |
| 427 * "ultimately backing" byte array is not divisible by 2. In plain terms, | |
| 428 * this constructor throws [IllegalArgumentException] if the specified | |
| 429 * region does not contain an integral number of "int16s," or if it | |
| 430 * is not "int16-aligned." | |
| 431 */ | |
| 432 Int16List.view(ByteArray array, [int start, int length]); | |
| 433 } | |
| 434 | |
| 435 | |
| 436 /** | |
| 437 * A fixed-length list of 16-bit unsigned integers that is viewable as a | |
| 438 * [ByteArray]. For long lists, this implementation will be considerably | |
| 439 * more space- and time-efficient than the default [List] implementation. | |
| 440 */ | |
| 441 interface Uint16List extends List<int>, ByteArrayViewable | |
| 442 default _Uint16ArrayFactory { | |
| 443 /** | |
| 444 * Creates a [Uint16List] of the specified length (in elements), all | |
| 445 * of whose elements are initially zero. | |
| 446 */ | |
| 447 Uint16List(int length); | |
| 448 | |
| 449 /** | |
| 450 * Creates a [Uint16List] _view_ of the specified region in | |
| 451 * the specified byte [array]. Changes in the [Uint16List] will be | |
| 452 * visible in the byte array and vice versa. If the [start] index of the | |
| 453 * region is not specified, it defaults to zero (the first byte in the byte | |
| 454 * array). If the length is not specified, it defaults to null, which | |
| 455 * indicates that the view extends to the end of the byte array. | |
| 456 * | |
| 457 * Throws [IllegalArgumentException] if the length of the specified region | |
| 458 * is not divisible by 2 (the size of a "uint16" in bytes), or if the | |
| 459 * [start] of the region is not divisible by 2. If, however, [array] | |
| 460 * is a view of another byte array, this constructor will throw | |
| 461 * [IllegalArgumentException] if the implicit starting position in the | |
| 462 * "ultimately backing" byte array is not divisible by 2. In plain terms, | |
| 463 * this constructor throws [IllegalArgumentException] if the specified | |
| 464 * region does not contain an integral number of "uint16s," or if it | |
| 465 * is not "uint16-aligned." | |
| 466 */ | |
| 467 Uint16List.view(ByteArray array, [int start, int length]); | |
| 468 } | |
| 469 | |
| 470 | |
| 471 /** | |
| 472 * A fixed-length list of 32-bit signed integers that is viewable as a | |
| 473 * [ByteArray]. For long lists, this implementation will be considerably | |
| 474 * more space- and time-efficient than the default [List] implementation. | |
| 475 */ | |
| 476 interface Int32List extends List<int>, ByteArrayViewable | |
| 477 default _Int32ArrayFactory { | |
| 478 /** | |
| 479 * Creates an [Int32List] of the specified length (in elements), all of | |
| 480 * whose elements are initially zero. | |
| 481 */ | |
| 482 Int32List(int length); | |
| 483 | |
| 484 /** | |
| 485 * Creates an [Int32List] _view_ of the specified region in the specified | |
| 486 * byte [array]. Changes in the [Int32List] will be visible in the byte | |
| 487 * array and vice versa. If the [start] index of the region is not specified, | |
| 488 * it defaults to zero (the first byte in the byte array). If the length is | |
| 489 * not specified, it defaults to null, which indicates that the view extends | |
| 490 * to the end of the byte array. | |
| 491 * | |
| 492 * Throws [IllegalArgumentException] if the length of the specified region | |
| 493 * is not divisible by 4 (the size of an "int32" in bytes), or if the | |
| 494 * [start] of the region is not divisible by 4. If, however, [array] | |
| 495 * is a view of another byte array, this constructor will throw | |
| 496 * [IllegalArgumentException] if the implicit starting position in the | |
| 497 * "ultimately backing" byte array is not divisible by 4. In plain terms, | |
| 498 * this constructor throws [IllegalArgumentException] if the specified | |
| 499 * region does not contain an integral number of "int32s," or if it | |
| 500 * is not "int32-aligned." | |
| 501 */ | |
| 502 Int32List.view(ByteArray array, [int start, int length]); | |
| 503 } | |
| 504 | |
| 505 | |
| 506 /** | |
| 507 * A fixed-length list of 32-bit unsigned integers that is viewable as a | |
| 508 * [ByteArray]. For long lists, this implementation will be considerably | |
| 509 * more space- and time-efficient than the default [List] implementation. | |
| 510 */ | |
| 511 interface Uint32List extends List<int>, ByteArrayViewable | |
| 512 default _Uint32ArrayFactory { | |
| 513 /** | |
| 514 * Creates a [Uint32List] of the specified length (in elements), all | |
| 515 * of whose elements are initially zero. | |
| 516 */ | |
| 517 Uint32List(int length); | |
| 518 | |
| 519 /** | |
| 520 * Creates a [Uint32List] _view_ of the specified region in | |
| 521 * the specified byte [array]. Changes in the [Uint32] will be | |
| 522 * visible in the byte array and vice versa. If the [start] index of the | |
| 523 * region is not specified, it defaults to zero (the first byte in the byte | |
| 524 * array). If the length is not specified, it defaults to null, which | |
| 525 * indicates that the view extends to the end of the byte array. | |
| 526 * | |
| 527 * Throws [IllegalArgumentException] if the length of the specified region | |
| 528 * is not divisible by 4 (the size of a "uint32" in bytes), or if the | |
| 529 * [start] of the region is not divisible by 4. If, however, [array] | |
| 530 * is a view of another byte array, this constructor will throw | |
| 531 * [IllegalArgumentException] if the implicit starting position in the | |
| 532 * "ultimately backing" byte array is not divisible by 4. In plain terms, | |
| 533 * this constructor throws [IllegalArgumentException] if the specified | |
| 534 * region does not contain an integral number of "uint32s," or if it | |
| 535 * is not "uint32-aligned." | |
| 536 */ | |
| 537 Uint32List.view(ByteArray array, [int start, int length]); | |
| 538 } | |
| 539 | |
| 540 | |
| 541 /** | |
| 542 * A fixed-length list of 64-bit signed integers that is viewable as a | |
| 543 * [ByteArray]. For long lists, this implementation will be considerably | |
| 544 * more space- and time-efficient than the default [List] implementation. | |
| 545 */ | |
| 546 interface Int64List extends List<int>, ByteArrayViewable | |
| 547 default _Int64ArrayFactory { | |
| 548 /** | |
| 549 * Creates an [Int64List] of the specified length (in elements), all of | |
| 550 * whose elements are initially zero. | |
| 551 */ | |
| 552 Int64List(int length); | |
| 553 | |
| 554 /** | |
| 555 * Creates an [Int64List] _view_ of the specified region in the specified | |
| 556 * byte [array]. Changes in the [Int64List] will be visible in the byte | |
| 557 * array and vice versa. If the [start] index of the region is not specified, | |
| 558 * it defaults to zero (the first byte in the byte array). If the length is | |
| 559 * not specified, it defaults to null, which indicates that the view extends | |
| 560 * to the end of the byte array. | |
| 561 * | |
| 562 * Throws [IllegalArgumentException] if the length of the specified region | |
| 563 * is not divisible by 8 (the size of an "int64" in bytes), or if the | |
| 564 * [start] of the region is not divisible by 8. If, however, [array] | |
| 565 * is a view of another byte array, this constructor will throw | |
| 566 * [IllegalArgumentException] if the implicit starting position in the | |
| 567 * "ultimately backing" byte array is not divisible by 8. In plain terms, | |
| 568 * this constructor throws [IllegalArgumentException] if the specified | |
| 569 * region does not contain an integral number of "int64s," or if it | |
| 570 * is not "int64-aligned." | |
| 571 */ | |
| 572 Int64List.view(ByteArray array, [int start, int length]); | |
| 573 } | |
| 574 | |
| 575 | |
| 576 /** | |
| 577 * A fixed-length list of 64-bit unsigned integers that is viewable as a | |
| 578 * [ByteArray]. For long lists, this implementation will be considerably | |
| 579 * more space- and time-efficient than the default [List] implementation. | |
| 580 */ | |
| 581 interface Uint64List extends List<int>, ByteArrayViewable | |
| 582 default _Uint64ArrayFactory { | |
| 583 /** | |
| 584 * Creates a [Uint64List] of the specified length (in elements), all | |
| 585 * of whose elements are initially zero. | |
| 586 */ | |
| 587 Uint64List(int length); | |
| 588 | |
| 589 /** | |
| 590 * Creates an [Uint64List] _view_ of the specified region in | |
| 591 * the specified byte [array]. Changes in the [Uint64List] will be | |
| 592 * visible in the byte array and vice versa. If the [start] index of the | |
| 593 * region is not specified, it defaults to zero (the first byte in the byte | |
| 594 * array). If the length is not specified, it defaults to null, which | |
| 595 * indicates that the view extends to the end of the byte array. | |
| 596 * | |
| 597 * Throws [IllegalArgumentException] if the length of the specified region | |
| 598 * is not divisible by 8 (the size of a "uint64" in bytes), or if the | |
| 599 * [start] of the region is not divisible by 8. If, however, [array] | |
| 600 * is a view of another byte array, this constructor will throw | |
| 601 * [IllegalArgumentException] if the implicit starting position in the | |
| 602 * "ultimately backing" byte array is not divisible by 8. In plain terms, | |
| 603 * this constructor throws [IllegalArgumentException] if the specified | |
| 604 * region does not contain an integral number of "uint64s," or if it | |
| 605 * is not "uint64-aligned." | |
| 606 */ | |
| 607 Uint64List.view(ByteArray array, [int start, int length]); | |
| 608 } | |
| 609 | |
| 610 | |
| 611 /** | |
| 612 * A fixed-length list of IEEE 754 single-precision binary floating-point | |
| 613 * numbers that is viewable as a [ByteArray]. For long lists, this | |
| 614 * implementation will be considerably more space- and time-efficient than | |
| 615 * the default [List] implementation. | |
| 616 */ | |
| 617 interface Float32List extends List<double>, ByteArrayViewable | |
| 618 default _Float32ArrayFactory { | |
| 619 /** | |
| 620 * Creates a [Float32List] of the specified length (in elements), all of | |
| 621 * whose elements are initially zero. | |
| 622 */ | |
| 623 Float32List(int length); | |
| 624 | |
| 625 /** | |
| 626 * Creates a [Float32List] _view_ of the specified region in the specified | |
| 627 * byte [array]. Changes in the [Float32List] will be visible in the byte | |
| 628 * array and vice versa. If the [start] index of the region is not specified, | |
| 629 * it defaults to zero (the first byte in the byte array). If the length is | |
| 630 * not specified, it defaults to null, which indicates that the view extends | |
| 631 * to the end of the byte array. | |
| 632 * | |
| 633 * Throws [IllegalArgumentException] if the length of the specified region | |
| 634 * is not divisible by 4 (the size of a "float32" in bytes), or if the | |
| 635 * [start] of the region is not divisible by 4. If, however, [array] | |
| 636 * is a view of another byte array, this constructor will throw | |
| 637 * [IllegalArgumentException] if the implicit starting position in the | |
| 638 * "ultimately backing" byte array is not divisible by 4. In plain terms, | |
| 639 * this constructor throws [IllegalArgumentException] if the specified | |
| 640 * region does not contain an integral number of "float32s," or if it | |
| 641 * is not "float32-aligned." | |
| 642 */ | |
| 643 Float32List.view(ByteArray array, [int start, int length]); | |
| 644 } | |
| 645 | |
| 646 | |
| 647 /** | |
| 648 * A fixed-length list of IEEE 754 double-precision binary floating-point | |
| 649 * numbers that is viewable as a [ByteArray]. For long lists, this | |
| 650 * implementation will be considerably more space- and time-efficient than | |
| 651 * the default [List] implementation. | |
| 652 */ | |
| 653 interface Float64List extends List<double>, ByteArrayViewable | |
| 654 default _Float64ArrayFactory { | |
| 655 /** | |
| 656 * Creates a [Float64List] of the specified length (in elements), all of | |
| 657 * whose elements are initially zero. | |
| 658 */ | |
| 659 Float64List(int length); | |
| 660 | |
| 661 /** | |
| 662 * Creates a [Float64List] _view_ of the specified region in the specified | |
| 663 * byte [array]. Changes in the [Float64List] will be visible in the byte | |
| 664 * array and vice versa. If the [start] index of the region is not specified, | |
| 665 * it defaults to zero (the first byte in the byte array). If the length is | |
| 666 * not specified, it defaults to null, which indicates that the view extends | |
| 667 * to the end of the byte array. | |
| 668 * | |
| 669 * Throws [IllegalArgumentException] if the length of the specified region | |
| 670 * is not divisible by 8 (the size of a "float64" in bytes), or if the | |
| 671 * [start] of the region is not divisible by 8. If, however, [array] | |
| 672 * is a view of another byte array, this constructor will throw | |
| 673 * [IllegalArgumentException] if the implicit starting position in the | |
| 674 * "ultimately backing" byte array is not divisible by 8. In plain terms, | |
| 675 * this constructor throws [IllegalArgumentException] if the specified | |
| 676 * region does not contain an integral number of "float64s," or if it | |
| 677 * is not "float64-aligned." | |
| 678 */ | |
| 679 Float64List.view(ByteArray array, [int start, int length]); | |
| 680 } | |
| 681 | |
| 682 | |
| 683 class _Int8ArrayFactory { | |
| 684 factory Int8List(int length) { | |
| 685 return new _Int8Array(length); | 7 return new _Int8Array(length); |
| 686 } | 8 } |
| 687 | 9 |
| 688 factory Int8List.view(ByteArray array, [int start = 0, int length]) { | 10 /* patch */ factory Int8List.view(ByteArray array, |
| 11 [int start = 0, int length]) { |
| 689 return new _Int8ArrayView(array, start, length); | 12 return new _Int8ArrayView(array, start, length); |
| 690 } | 13 } |
| 691 } | 14 } |
| 692 | 15 |
| 693 | 16 |
| 694 class _Uint8ArrayFactory { | 17 patch class Uint8List { |
| 695 factory Uint8List(int length) { | 18 /* patch */ factory Uint8List(int length) { |
| 696 return new _Uint8Array(length); | 19 return new _Uint8Array(length); |
| 697 } | 20 } |
| 698 | 21 |
| 699 factory Uint8List.view(ByteArray array, [int start = 0, int length]) { | 22 /* patch */ factory Uint8List.view(ByteArray array, |
| 23 [int start = 0, int length]) { |
| 700 return new _Uint8ArrayView(array, start, length); | 24 return new _Uint8ArrayView(array, start, length); |
| 701 } | 25 } |
| 702 } | 26 } |
| 703 | 27 |
| 704 | 28 |
| 705 class _Int16ArrayFactory { | 29 patch class Int16List { |
| 706 factory Int16List(int length) { | 30 /* patch */ factory Int16List(int length) { |
| 707 return new _Int16Array(length); | 31 return new _Int16Array(length); |
| 708 } | 32 } |
| 709 | 33 |
| 710 factory Int16List.view(ByteArray array, [int start = 0, int length]) { | 34 /* patch */ factory Int16List.view(ByteArray array, [int start = 0, int length
]) { |
| 711 return new _Int16ArrayView(array, start, length); | 35 return new _Int16ArrayView(array, start, length); |
| 712 } | 36 } |
| 713 } | 37 } |
| 714 | 38 |
| 715 | 39 |
| 716 class _Uint16ArrayFactory { | 40 patch class Uint16List { |
| 717 factory Uint16List(int length) { | 41 /* patch */ factory Uint16List(int length) { |
| 718 return new _Uint16Array(length); | 42 return new _Uint16Array(length); |
| 719 } | 43 } |
| 720 | 44 |
| 721 factory Uint16List.view(ByteArray array, [int start = 0, int length]) { | 45 /* patch */ factory Uint16List.view(ByteArray array, [int start = 0, int lengt
h]) { |
| 722 return new _Uint16ArrayView(array, start, length); | 46 return new _Uint16ArrayView(array, start, length); |
| 723 } | 47 } |
| 724 } | 48 } |
| 725 | 49 |
| 726 | 50 |
| 727 class _Int32ArrayFactory { | 51 patch class Int32List { |
| 728 factory Int32List(int length) { | 52 /* patch */ factory Int32List(int length) { |
| 729 return new _Int32Array(length); | 53 return new _Int32Array(length); |
| 730 } | 54 } |
| 731 | 55 |
| 732 factory Int32List.view(ByteArray array, [int start = 0, int length]) { | 56 /* patch */ factory Int32List.view(ByteArray array, [int start = 0, int length
]) { |
| 733 return new _Int32ArrayView(array, start, length); | 57 return new _Int32ArrayView(array, start, length); |
| 734 } | 58 } |
| 735 } | 59 } |
| 736 | 60 |
| 737 | 61 |
| 738 class _Uint32ArrayFactory { | 62 patch class Uint32List { |
| 739 factory Uint32List(int length) { | 63 /* patch */ factory Uint32List(int length) { |
| 740 return new _Uint32Array(length); | 64 return new _Uint32Array(length); |
| 741 } | 65 } |
| 742 | 66 |
| 743 factory Uint32List.view(ByteArray array, [int start = 0, int length]) { | 67 /* patch */ factory Uint32List.view(ByteArray array, [int start = 0, int lengt
h]) { |
| 744 return new _Uint32ArrayView(array, start, length); | 68 return new _Uint32ArrayView(array, start, length); |
| 745 } | 69 } |
| 746 } | 70 } |
| 747 | 71 |
| 748 | 72 |
| 749 class _Int64ArrayFactory { | 73 patch class Int64List { |
| 750 factory Int64List(int length) { | 74 /* patch */ factory Int64List(int length) { |
| 751 return new _Int64Array(length); | 75 return new _Int64Array(length); |
| 752 } | 76 } |
| 753 | 77 |
| 754 factory Int64List.view(ByteArray array, [int start = 0, int length]) { | 78 /* patch */ factory Int64List.view(ByteArray array, [int start = 0, int length
]) { |
| 755 return new _Int64ArrayView(array, start, length); | 79 return new _Int64ArrayView(array, start, length); |
| 756 } | 80 } |
| 757 } | 81 } |
| 758 | 82 |
| 759 | 83 |
| 760 class _Uint64ArrayFactory { | 84 patch class Uint64List { |
| 761 factory Uint64List(int length) { | 85 /* patch */ factory Uint64List(int length) { |
| 762 return new _Uint64Array(length); | 86 return new _Uint64Array(length); |
| 763 } | 87 } |
| 764 | 88 |
| 765 factory Uint64List.view(ByteArray array, [int start = 0, int length]) { | 89 /* patch */ factory Uint64List.view(ByteArray array, [int start = 0, int lengt
h]) { |
| 766 return new _Uint64ArrayView(array, start, length); | 90 return new _Uint64ArrayView(array, start, length); |
| 767 } | 91 } |
| 768 } | 92 } |
| 769 | 93 |
| 770 | 94 |
| 771 class _Float32ArrayFactory { | 95 patch class Float32List { |
| 772 factory Float32List(int length) { | 96 /* patch */ factory Float32List(int length) { |
| 773 return new _Float32Array(length); | 97 return new _Float32Array(length); |
| 774 } | 98 } |
| 775 | 99 |
| 776 factory Float32List.view(ByteArray array, [int start = 0, int length]) { | 100 /* patch */ factory Float32List.view(ByteArray array, [int start = 0, int leng
th]) { |
| 777 return new _Float32ArrayView(array, start, length); | 101 return new _Float32ArrayView(array, start, length); |
| 778 } | 102 } |
| 779 } | 103 } |
| 780 | 104 |
| 781 | 105 |
| 782 class _Float64ArrayFactory { | 106 patch class Float64List { |
| 783 factory Float64List(int length) { | 107 /* patch */ factory Float64List(int length) { |
| 784 return new _Float64Array(length); | 108 return new _Float64Array(length); |
| 785 } | 109 } |
| 786 | 110 |
| 787 factory Float64List.view(ByteArray array, [int start = 0, int length]) { | 111 /* patch */ factory Float64List.view(ByteArray array, [int start = 0, int leng
th]) { |
| 788 return new _Float64ArrayView(array, start, length); | 112 return new _Float64ArrayView(array, start, length); |
| 789 } | 113 } |
| 790 } | 114 } |
| 791 | 115 |
| 792 | 116 |
| 793 abstract class _ByteArrayBase { | 117 abstract class _ByteArrayBase { |
| 794 abstract int lengthInBytes(); | 118 abstract int lengthInBytes(); |
| 795 | 119 |
| 796 abstract int bytesPerElement(); | 120 abstract int bytesPerElement(); |
| 797 | 121 |
| (...skipping 2288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3086 } | 2410 } |
| 3087 _rangeCheck(this.length, start, length); | 2411 _rangeCheck(this.length, start, length); |
| 3088 return _array.subByteArray(_offset + start, length); | 2412 return _array.subByteArray(_offset + start, length); |
| 3089 } | 2413 } |
| 3090 | 2414 |
| 3091 static const int _BYTES_PER_ELEMENT = 8; | 2415 static const int _BYTES_PER_ELEMENT = 8; |
| 3092 final ByteArray _array; | 2416 final ByteArray _array; |
| 3093 final int _offset; | 2417 final int _offset; |
| 3094 final int _length; | 2418 final int _length; |
| 3095 } | 2419 } |
| OLD | NEW |