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

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 21562002: Improve performance of Dart_ListGetAsBytes. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: addressed comments Created 7 years, 4 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 #include "bin/builtin.h" 5 #include "bin/builtin.h"
6 #include "include/dart_api.h" 6 #include "include/dart_api.h"
7 #include "include/dart_mirrors_api.h" 7 #include "include/dart_mirrors_api.h"
8 #include "include/dart_native_api.h" 8 #include "include/dart_native_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/json.h" 10 #include "platform/json.h"
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 result = Dart_ListSetAsBytes(list_access_test_obj, 0, native_array, 3); 825 result = Dart_ListSetAsBytes(list_access_test_obj, 0, native_array, 3);
826 EXPECT(Dart_IsError(result)); 826 EXPECT(Dart_IsError(result));
827 EXPECT(Dart_IsUnhandledExceptionError(result)); 827 EXPECT(Dart_IsUnhandledExceptionError(result));
828 828
829 result = Dart_ListSetAt(list_access_test_obj, 0, Dart_NewInteger(42)); 829 result = Dart_ListSetAt(list_access_test_obj, 0, Dart_NewInteger(42));
830 EXPECT(Dart_IsError(result)); 830 EXPECT(Dart_IsError(result));
831 EXPECT(Dart_IsUnhandledExceptionError(result)); 831 EXPECT(Dart_IsUnhandledExceptionError(result));
832 } 832 }
833 833
834 834
835 TEST_CASE(TypedDataViewListGetAsBytes) {
836 const int kSize = 1000;
837
838 const char* kScriptChars =
839 "import 'dart:typed_data';\n"
840 "List main(int size) {\n"
841 " var a = new Int8List(size);\n"
842 " var view = new Int8List.view(a.buffer, 0, size);\n"
843 " return view;\n"
844 "}\n";
845 // Create a test library and Load up a test script in it.
846 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
847
848 // Test with a typed data view object.
849 Dart_Handle dart_args[1];
850 dart_args[0] = Dart_NewInteger(kSize);
851 Dart_Handle view_obj = Dart_Invoke(lib, NewString("main"), 1, dart_args);
852 EXPECT_VALID(view_obj);
853 for (intptr_t i = 0; i < kSize; ++i) {
854 EXPECT_VALID(Dart_ListSetAt(view_obj, i, Dart_NewInteger(i & 0xff)));
855 }
856 uint8_t* data = new uint8_t[kSize];
857 EXPECT_VALID(Dart_ListGetAsBytes(view_obj, 0, data, kSize));
858 for (intptr_t i = 0; i < kSize; ++i) {
859 EXPECT_EQ(i & 0xff, data[i]);
860 }
861
862 Dart_Handle result = Dart_ListGetAsBytes(view_obj, 0, data, kSize + 1);
863 EXPECT(Dart_IsError(result));
864 delete[] data;
865 }
866
867
835 TEST_CASE(TypedDataAccess) { 868 TEST_CASE(TypedDataAccess) {
836 EXPECT_EQ(Dart_TypedData_kInvalid, 869 EXPECT_EQ(Dart_TypedData_kInvalid,
837 Dart_GetTypeOfTypedData(Dart_True())); 870 Dart_GetTypeOfTypedData(Dart_True()));
838 EXPECT_EQ(Dart_TypedData_kInvalid, 871 EXPECT_EQ(Dart_TypedData_kInvalid,
839 Dart_GetTypeOfExternalTypedData(Dart_False())); 872 Dart_GetTypeOfExternalTypedData(Dart_False()));
840 Dart_Handle byte_array1 = Dart_NewTypedData(Dart_TypedData_kUint8, 10); 873 Dart_Handle byte_array1 = Dart_NewTypedData(Dart_TypedData_kUint8, 10);
841 EXPECT_VALID(byte_array1); 874 EXPECT_VALID(byte_array1);
842 EXPECT_EQ(Dart_TypedData_kUint8, 875 EXPECT_EQ(Dart_TypedData_kUint8,
843 Dart_GetTypeOfTypedData(byte_array1)); 876 Dart_GetTypeOfTypedData(byte_array1));
844 EXPECT_EQ(Dart_TypedData_kInvalid, 877 EXPECT_EQ(Dart_TypedData_kInvalid,
(...skipping 7415 matching lines...) Expand 10 before | Expand all | Expand 10 after
8260 EXPECT(Dart_IsError(Dart_GetClass(lib, NewString("baw")))); 8293 EXPECT(Dart_IsError(Dart_GetClass(lib, NewString("baw"))));
8261 // Variables foo1 and foo2 are unambiguous. 8294 // Variables foo1 and foo2 are unambiguous.
8262 EXPECT(!Dart_IsError(Dart_LookupVariable(lib, NewString("foo1")))); 8295 EXPECT(!Dart_IsError(Dart_LookupVariable(lib, NewString("foo1"))));
8263 EXPECT(!Dart_IsError(Dart_LookupVariable(lib, NewString("foo2")))); 8296 EXPECT(!Dart_IsError(Dart_LookupVariable(lib, NewString("foo2"))));
8264 // Functions bar1 and bar2 are unambiguous. 8297 // Functions bar1 and bar2 are unambiguous.
8265 EXPECT(!Dart_IsError(Dart_LookupFunction(lib, NewString("bar1")))); 8298 EXPECT(!Dart_IsError(Dart_LookupFunction(lib, NewString("bar1"))));
8266 EXPECT(!Dart_IsError(Dart_LookupFunction(lib, NewString("bar2")))); 8299 EXPECT(!Dart_IsError(Dart_LookupFunction(lib, NewString("bar2"))));
8267 } 8300 }
8268 8301
8269 } // namespace dart 8302 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698