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

Unified Diff: runtime/bin/socket_impl.dart

Issue 9254022: Make sure to use an ObjectArray when writing to a socket (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Really address the review comments from ager@ Created 8 years, 11 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 | « runtime/bin/file_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_impl.dart
diff --git a/runtime/bin/socket_impl.dart b/runtime/bin/socket_impl.dart
index b462dadc11f98a23eb191ccef6c8a9c640422344..14d3b500c5ba001c8b4ed906e59865d0d7a2b543 100644
--- a/runtime/bin/socket_impl.dart
+++ b/runtime/bin/socket_impl.dart
@@ -1,4 +1,4 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@@ -322,7 +322,23 @@ class _Socket extends _SocketBase implements Socket {
if ((offset + bytes) > buffer.length) {
throw new IndexOutOfRangeException(offset + bytes);
}
- var bytes_written = _writeList(buffer, offset, bytes);
+ // When using the Dart C API access to ObjectArray by index is
+ // currently much faster. This function will make a copy of the
+ // supplied List to an ObjectArray if it isn't already.
+ ObjectArray outBuffer;
+ int outOffset = offset;
+ if (buffer is ObjectArray) {
+ outBuffer = buffer;
+ } else {
+ outBuffer = new ObjectArray(bytes);
+ outOffset = 0;
+ int j = offset;
+ for (int i = 0; i < bytes; i++) {
+ outBuffer[i] = buffer[j];
+ j++;
+ }
+ }
+ var bytes_written = _writeList(outBuffer, outOffset, bytes);
if (bytes_written < 0) {
// If writing fails we return 0 as the number of bytes and
// report the error on the error handler.
« no previous file with comments | « runtime/bin/file_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698