aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/js/js_generator.cc
diff options
context:
space:
mode:
authorGravatar Adam Cozzette <acozzette@gmail.com>2016-09-21 10:39:23 -0700
committerGravatar Bo Yang <teboring@google.com>2016-10-10 11:43:48 -0700
commitf7bb8477a8e925090a2209097f5fbb62b1f7f919 (patch)
treeca7fd1494e39e645b4c8f34fdbad60f2640ff9bc /src/google/protobuf/compiler/js/js_generator.cc
parent31dd4998df27898f61c3f3b32b08cfbbd1fc881f (diff)
Fixed quadratic behavior in JSPB deserialization of repeated fields (#2117) (#2146)
Currently deserialization of a non-packed binary repeated field is quadratic in the number of elements, because each time we parse a new element we copy over all elements we have parsed so far. This CL fixes the performance problem by having the generated deserialization code just call addX() instead of using getX() and setX().
Diffstat (limited to 'src/google/protobuf/compiler/js/js_generator.cc')
-rwxr-xr-xsrc/google/protobuf/compiler/js/js_generator.cc10
1 files changed, 3 insertions, 7 deletions
diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc
index 1a882057..fec465fe 100755
--- a/src/google/protobuf/compiler/js/js_generator.cc
+++ b/src/google/protobuf/compiler/js/js_generator.cc
@@ -2850,13 +2850,9 @@ void Generator::GenerateClassDeserializeBinaryField(
}
if (field->is_repeated() && !field->is_packed()) {
- // Repeated fields receive a |value| one at at a time; append to array
- // returned by get$name$(). Annoyingly, we have to call 'set' after
- // changing the array.
- printer->Print(" msg.get$name$().push(value);\n", "name",
- JSGetterName(options, field));
- printer->Print(" msg.set$name$(msg.get$name$());\n", "name",
- JSGetterName(options, field));
+ printer->Print(
+ " msg.add$name$(value);\n", "name",
+ JSGetterName(options, field, BYTES_DEFAULT, /* drop_list = */ true));
} else {
// Singular fields, and packed repeated fields, receive a |value| either
// as the field's value or as the array of all the field's values; set