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

Side by Side Diff: runtime/bin/socket_impl.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 5
6 class _SocketBase { 6 class _SocketBase {
7 // Bit flags used when communicating between the eventhandler and 7 // Bit flags used when communicating between the eventhandler and
8 // dart code. The EVENT flags are used to indicate events of 8 // dart code. The EVENT flags are used to indicate events of
9 // interest when sending a message from dart code to the 9 // interest when sending a message from dart code to the
10 // eventhandler. When receiving a message from the eventhandler the 10 // eventhandler. When receiving a message from the eventhandler the
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 299 }
300 if (offset < 0) { 300 if (offset < 0) {
301 throw new IndexOutOfRangeException(offset); 301 throw new IndexOutOfRangeException(offset);
302 } 302 }
303 if (bytes < 0) { 303 if (bytes < 0) {
304 throw new IndexOutOfRangeException(bytes); 304 throw new IndexOutOfRangeException(bytes);
305 } 305 }
306 if ((offset + bytes) > buffer.length) { 306 if ((offset + bytes) > buffer.length) {
307 throw new IndexOutOfRangeException(offset + bytes); 307 throw new IndexOutOfRangeException(offset + bytes);
308 } 308 }
309 // When using the Dart C API access to ObjectArray by index is 309 // When using the Dart C API to access raw data, using a ByteArray is
310 // currently much faster. This function will make a copy of the 310 // currently much faster. This function will make a copy of the
311 // supplied List to an ObjectArray if it isn't already. 311 // supplied List to a ByteArray if it isn't already.
312 ObjectArray outBuffer; 312 List outBuffer;
313 int outOffset = offset; 313 int outOffset = offset;
314 if (buffer is ObjectArray) { 314 if (buffer is ByteArray || buffer is ObjectArray) {
315 outBuffer = buffer; 315 outBuffer = buffer;
316 } else { 316 } else {
317 outBuffer = new ObjectArray(bytes); 317 outBuffer = new ByteArray(bytes);
318 outOffset = 0; 318 outOffset = 0;
319 int j = offset; 319 int j = offset;
320 for (int i = 0; i < bytes; i++) { 320 for (int i = 0; i < bytes; i++) {
321 outBuffer[i] = buffer[j]; 321 int value = buffer[j];
322 if (value is! int) {
323 throw new FileIOException(
324 "List element is not an integer at index $j");
325 }
326 outBuffer[i] = value;
322 j++; 327 j++;
323 } 328 }
324 } 329 }
325 var bytes_written = _writeList(outBuffer, outOffset, bytes); 330 var bytes_written = _writeList(outBuffer, outOffset, bytes);
326 if (bytes_written < 0) { 331 if (bytes_written < 0) {
327 // If writing fails we return 0 as the number of bytes and 332 // If writing fails we return 0 as the number of bytes and
328 // report the error on the error handler. 333 // report the error on the error handler.
329 bytes_written = 0; 334 bytes_written = 0;
330 _reportError(); 335 _reportError();
331 } 336 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 bool _seenFirstOutEvent = false; 460 bool _seenFirstOutEvent = false;
456 bool _closedRead = false; 461 bool _closedRead = false;
457 bool _closedWrite = false; 462 bool _closedWrite = false;
458 bool _pipe = false; 463 bool _pipe = false;
459 Function _clientConnectHandler; 464 Function _clientConnectHandler;
460 Function _clientWriteHandler; 465 Function _clientWriteHandler;
461 SocketInputStream _inputStream; 466 SocketInputStream _inputStream;
462 SocketOutputStream _outputStream; 467 SocketOutputStream _outputStream;
463 } 468 }
464 469
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698