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

Unified Diff: mojo/public/tools/bindings/generators/mojom_python_generator.py

Issue 548343005: mojo: Specialize native type arrays. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Follow review Created 6 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 | « mojo/public/python/mojo/bindings/descriptor.py ('k') | mojo/python/tests/bindings_structs_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/tools/bindings/generators/mojom_python_generator.py
diff --git a/mojo/public/tools/bindings/generators/mojom_python_generator.py b/mojo/public/tools/bindings/generators/mojom_python_generator.py
index 9417298d4b3cf5d01f8b098658b4379ebe3090de..75992a3842cada0491294bb7d13b610e073035d0 100644
--- a/mojo/public/tools/bindings/generators/mojom_python_generator.py
+++ b/mojo/public/tools/bindings/generators/mojom_python_generator.py
@@ -37,6 +37,20 @@ _kind_to_type = {
mojom.NULLABLE_SHAREDBUFFER: "_descriptor.TYPE_NULLABLE_HANDLE",
}
+# int64 integers are not handled by array.array. int64/uint64 array are
+# supported but storage is not optimized (ie. they are plain python list, not
+# array.array)
+_kind_to_typecode = {
+ mojom.INT8: "'b'",
+ mojom.UINT8: "'B'",
+ mojom.INT16: "'h'",
+ mojom.UINT16: "'H'",
+ mojom.INT32: "'i'",
+ mojom.UINT32: "'I'",
+ mojom.FLOAT: "'f'",
+ mojom.DOUBLE: "'d'",
+}
+
def NameToComponent(name):
# insert '_' between anything and a Title name (e.g, HTTPEntry2FooBar ->
@@ -99,12 +113,18 @@ def GetStructClass(kind):
def GetFieldType(kind, field=None):
if mojom.IsAnyArrayKind(kind):
- arguments = [ GetFieldType(kind.kind) ]
+ if kind.kind in _kind_to_typecode:
+ arguments = [ _kind_to_typecode[kind.kind] ]
+ else:
+ arguments = [ GetFieldType(kind.kind) ]
if mojom.IsNullableKind(kind):
arguments.append("nullable=True")
if mojom.IsFixedArrayKind(kind):
arguments.append("length=%d" % kind.length)
- return "_descriptor.ArrayType(%s)" % ", ".join(arguments)
+ if kind.kind in _kind_to_typecode:
+ return "_descriptor.NativeArrayType(%s)" % ", ".join(arguments)
+ else:
+ return "_descriptor.PointerArrayType(%s)" % ", ".join(arguments)
if mojom.IsStructKind(kind):
arguments = [ GetStructClass(kind) ]
« no previous file with comments | « mojo/public/python/mojo/bindings/descriptor.py ('k') | mojo/python/tests/bindings_structs_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698