Skip to content

Commit

Permalink
feat: optimize insert for class RepeatedComposite. (#95)
Browse files Browse the repository at this point in the history
Use a standard Python list insert on the target list
to replace a loop using pop and extend.

Co-authored-by: Bob Hancock <rwh@google.com>
  • Loading branch information
bobhancock and bobhancockg committed Aug 7, 2020
1 parent dc28bbb commit 86790e3
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions proto/marshal/collections/repeated.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,4 @@ def __setitem__(self, key, value):
def insert(self, index: int, value):
"""Insert ``value`` in the sequence before ``index``."""
pb_value = self._marshal.to_proto(self._pb_type, value, strict=True)

# Protocol buffers does not define a useful insert, so we have
# to pop everything after this point off the list and reload it.
after = [pb_value]
while self.pb[index:]:
after.append(self.pb.pop(index))
self.pb.extend(after)
self.pb.insert(index, pb_value)

0 comments on commit 86790e3

Please sign in to comment.