@@ -16,15 +16,17 @@ public static String genArray(Class clazz) {
1616 append (lines , "{{comp}}[] arr = ({{comp}}[])obj;" );
1717 append (lines , "if (arr.length == 0) { stream.writeEmptyArray(); return; }" );
1818 append (lines , "stream.startArray();" );
19- append (lines , "for ( int i = 0; i < arr.length; i++) { " );
19+ append (lines , "int i = 0;" );
2020 append (lines , "{{op}}" );
21+ append (lines , "while (i < arr.length) {" );
2122 append (lines , "stream.writeMore();" );
23+ append (lines , "{{op}}" );
2224 append (lines , "}" );
2325 append (lines , "stream.endArray();" );
2426 append (lines , "}" );
2527 return lines .toString ()
2628 .replace ("{{comp}}" , compType .getCanonicalName ())
27- .replace ("{{op}}" , CodegenImplNative .genWriteOp ("arr[i]" , compType ));
29+ .replace ("{{op}}" , CodegenImplNative .genWriteOp ("arr[i++ ]" , compType ));
2830 }
2931
3032 private static void append (StringBuilder lines , String str ) {
@@ -59,10 +61,9 @@ private static String genCollection(Class clazz, Type compType) {
5961 append (lines , "if (!iter.hasNext()) { stream.writeEmptyArray(); return; }" );
6062 append (lines , "stream.startArray();" );
6163 append (lines , "{{op}}" );
62- append (lines , "stream.writeMore();" );
6364 append (lines , "while (iter.hasNext()) {" );
64- append (lines , "{{op}}" );
6565 append (lines , "stream.writeMore();" );
66+ append (lines , "{{op}}" );
6667 append (lines , "}" );
6768 append (lines , "stream.endArray();" );
6869 append (lines , "}" );
0 commit comments