diff options
author | Ficus Kirkpatrick <ficus@android.com> | 2013-04-09 00:19:08 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2013-04-09 00:19:09 +0000 |
commit | 4349e11df9a06178b8106bb05f61b4d508b5d172 (patch) | |
tree | d6b265110ec1c8ba69aa46b5987b197326c75d3b | |
parent | d4bb580f1bbeb108f3d750cce504921df0a4d535 (diff) | |
parent | 314a30293347a7a3d5dd032f08677d9e988721cf (diff) | |
download | protobuf-4349e11df9a06178b8106bb05f61b4d508b5d172.tar.gz protobuf-4349e11df9a06178b8106bb05f61b4d508b5d172.tar.bz2 protobuf-4349e11df9a06178b8106bb05f61b4d508b5d172.zip |
Merge "Don't use Arrays.copyOf in generated code."
3 files changed, 20 insertions, 4 deletions
diff --git a/src/google/protobuf/compiler/javanano/javanano_enum_field.cc b/src/google/protobuf/compiler/javanano/javanano_enum_field.cc index 2c6fd5de..a22aa6fd 100644 --- a/src/google/protobuf/compiler/javanano/javanano_enum_field.cc +++ b/src/google/protobuf/compiler/javanano/javanano_enum_field.cc @@ -166,7 +166,9 @@ GenerateParsingCode(io::Printer* printer) const { printer->Print(variables_, "int arrayLength = com.google.protobuf.nano.WireFormatNano.getRepeatedFieldArrayLength(input, $tag$);\n" "int i = this.$name$.length;\n" - "this.$name$ = java.util.Arrays.copyOf(this.$name$, this.$name$.length + arrayLength);\n" + "int[] newArray = new int[i + arrayLength];\n" + "System.arraycopy(this.$name$, 0, newArray, 0, i);\n" + "this.$name$ = newArray;\n" "for (; i < this.$name$.length - 1; i++) {\n" " this.$name$[i] = input.readInt32();\n" " input.readTag();\n" diff --git a/src/google/protobuf/compiler/javanano/javanano_message_field.cc b/src/google/protobuf/compiler/javanano/javanano_message_field.cc index 01529c81..ec9d995f 100644 --- a/src/google/protobuf/compiler/javanano/javanano_message_field.cc +++ b/src/google/protobuf/compiler/javanano/javanano_message_field.cc @@ -144,7 +144,9 @@ GenerateParsingCode(io::Printer* printer) const { printer->Print(variables_, "int arrayLength = com.google.protobuf.nano.WireFormatNano.getRepeatedFieldArrayLength(input, $tag$);\n" "int i = this.$name$.length;\n" - "this.$name$ = java.util.Arrays.copyOf(this.$name$, i + arrayLength);\n" + "$type$[] newArray = new $type$[i + arrayLength];\n" + "System.arraycopy(this.$name$, 0, newArray, 0, i);\n" + "this.$name$ = newArray;\n" "for (; i < this.$name$.length - 1; i++) {\n" " this.$name$[i] = new $type$();\n"); diff --git a/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc b/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc index f5b25b68..1cf90662 100644 --- a/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc +++ b/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc @@ -391,8 +391,20 @@ GenerateParsingCode(io::Printer* printer) const { } else { printer->Print(variables_, "int arrayLength = com.google.protobuf.nano.WireFormatNano.getRepeatedFieldArrayLength(input, $tag$);\n" - "int i = this.$name$.length;\n" - "this.$name$ = java.util.Arrays.copyOf(this.$name$, this.$name$.length + arrayLength);\n" + "int i = this.$name$.length;\n"); + + if (GetJavaType(descriptor_) == JAVATYPE_BYTES) { + printer->Print(variables_, + "byte[][] newArray = new byte[i + arrayLength][];\n" + "System.arraycopy(this.$name$, 0, newArray, 0, i);\n" + "this.$name$ = newArray;\n"); + } else { + printer->Print(variables_, + "$type$[] newArray = new $type$[i + arrayLength];\n" + "System.arraycopy(this.$name$, 0, newArray, 0, i);\n" + "this.$name$ = newArray;\n"); + } + printer->Print(variables_, "for (; i < this.$name$.length - 1; i++) {\n" " this.$name$[i] = input.read$capitalized_type$();\n" " input.readTag();\n" |