Commit fbbe842a authored by Ficus Kirkpatrick's avatar Ficus Kirkpatrick Committed by Android Git Automerger

am e0ee97ea: Merge "Don\'t use Arrays.copyOf in generated code."

* commit 'e0ee97eaac9a0f3d74c42315a109cdc25f2fddc0':
  Don't use Arrays.copyOf in generated code.
parents 12ac3a7e 4349e11d
...@@ -166,7 +166,9 @@ GenerateParsingCode(io::Printer* printer) const { ...@@ -166,7 +166,9 @@ GenerateParsingCode(io::Printer* printer) const {
printer->Print(variables_, printer->Print(variables_,
"int arrayLength = com.google.protobuf.nano.WireFormatNano.getRepeatedFieldArrayLength(input, $tag$);\n" "int arrayLength = com.google.protobuf.nano.WireFormatNano.getRepeatedFieldArrayLength(input, $tag$);\n"
"int i = this.$name$.length;\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" "for (; i < this.$name$.length - 1; i++) {\n"
" this.$name$[i] = input.readInt32();\n" " this.$name$[i] = input.readInt32();\n"
" input.readTag();\n" " input.readTag();\n"
......
...@@ -144,7 +144,9 @@ GenerateParsingCode(io::Printer* printer) const { ...@@ -144,7 +144,9 @@ GenerateParsingCode(io::Printer* printer) const {
printer->Print(variables_, printer->Print(variables_,
"int arrayLength = com.google.protobuf.nano.WireFormatNano.getRepeatedFieldArrayLength(input, $tag$);\n" "int arrayLength = com.google.protobuf.nano.WireFormatNano.getRepeatedFieldArrayLength(input, $tag$);\n"
"int i = this.$name$.length;\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" "for (; i < this.$name$.length - 1; i++) {\n"
" this.$name$[i] = new $type$();\n"); " this.$name$[i] = new $type$();\n");
......
...@@ -391,8 +391,20 @@ GenerateParsingCode(io::Printer* printer) const { ...@@ -391,8 +391,20 @@ GenerateParsingCode(io::Printer* printer) const {
} else { } else {
printer->Print(variables_, printer->Print(variables_,
"int arrayLength = com.google.protobuf.nano.WireFormatNano.getRepeatedFieldArrayLength(input, $tag$);\n" "int arrayLength = com.google.protobuf.nano.WireFormatNano.getRepeatedFieldArrayLength(input, $tag$);\n"
"int i = this.$name$.length;\n" "int i = this.$name$.length;\n");
"this.$name$ = java.util.Arrays.copyOf(this.$name$, this.$name$.length + arrayLength);\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" "for (; i < this.$name$.length - 1; i++) {\n"
" this.$name$[i] = input.read$capitalized_type$();\n" " this.$name$[i] = input.read$capitalized_type$();\n"
" input.readTag();\n" " input.readTag();\n"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment