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

Unified Diff: runtime/bin/common.dart

Issue 11023003: Clean up file implementation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 8 years, 3 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 | runtime/bin/directory_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/common.dart
diff --git a/runtime/bin/common.dart b/runtime/bin/common.dart
index d1abe6a50ed1fb83b6497da11eca9d05380a810a..7f2da974a16d1d35115b5574bc4b637f01c61e0f 100644
--- a/runtime/bin/common.dart
+++ b/runtime/bin/common.dart
@@ -2,6 +2,16 @@
// 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.
+// Constants used when working with native ports.
+const int _SUCCESS_RESPONSE = 0;
+const int _ILLEGAL_ARGUMENT_RESPONSE = 1;
+const int _OSERROR_RESPONSE = 2;
+const int _FILE_CLOSED_RESPONSE = 3;
+
+const int _ERROR_RESPONSE_ERROR_TYPE = 0;
+const int _OSERROR_RESPONSE_ERROR_CODE = 1;
+const int _OSERROR_RESPONSE_MESSAGE = 2;
+
/**
* An [OSError] object holds information about an error from the
* operating system.
@@ -51,29 +61,32 @@ class OSError {
bool _isBuiltinList(List buffer) native "Common_IsBuiltinList";
+// Object for holding a buffer and an offset.
+class _BufferAndOffset {
+ _BufferAndOffset(List this.buffer, int this.offset);
+ List buffer;
+ int offset;
+}
+
+
// Ensure that the input List can be serialized through a native port.
// Only builtin Lists can be serialized through. If user-defined Lists
// get here, the contents is copied to a Uint8List. This has the added
// benefit that it is faster to access from the C code as well.
-List _ensureFastAndSerializableBuffer(
+_BufferAndOffset _ensureFastAndSerializableBuffer(
List buffer, int offset, int bytes) {
- List outBuffer;
- int outOffset = offset;
if (buffer is Uint8List || _isBuiltinList(buffer)) {
- outBuffer = buffer;
- } else {
- outBuffer = new Uint8List(bytes);
- outOffset = 0;
- int j = offset;
- for (int i = 0; i < bytes; i++) {
- int value = buffer[j];
- if (value is! int) {
- throw new FileIOException(
- "List element is not an integer at index $j");
- }
- outBuffer[i] = value;
- j++;
+ return new _BufferAndOffset(buffer, offset);
+ }
+ var newBuffer = new Uint8List(bytes);
+ int j = offset;
+ for (int i = 0; i < bytes; i++) {
+ int value = buffer[j];
+ if (value is! int) {
+ throw new FileIOException("List element is not an integer at index $j");
}
+ newBuffer[i] = value;
+ j++;
}
- return [outBuffer, outOffset];
+ return new _BufferAndOffset(newBuffer, 0);
}
« no previous file with comments | « no previous file | runtime/bin/directory_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698