Skip to content

Conversation

@osa1
Copy link
Member

@osa1 osa1 commented Oct 24, 2025

Update PbList methods that update the list with an Iterable argument to
avoid iterating the iterable twice: once for checking the element validity and
once again for actually adding the values.

Methods updated:

  • addAll
  • insertAll
  • replaceRange
  • setAll
  • setRange

Exception handling behavior before this PR was undefined (same as the standard
library List), and it's slightly changed with this PR:

  • addAll: previously if the iterator throws the list was left unchanged, now
    the elements until the exception will be added.

  • Other methods: exception behaviors are now the same as the standard library
    List methods.

    It's hard to tell whether the previous behavior was the same or different
    with the standard library List methods, as the exception behavior of those
    are undefined.

To avoid allocating new iterators when a check function is not available, we
have conditionals in each of these methods and call the standard library List
methods directly when there isn't a check function.

Fixes #730.


cl/823443311

@osa1 osa1 requested a review from sigurdm October 24, 2025 10:14
@osa1 osa1 marked this pull request as ready for review October 24, 2025 10:15
@osa1
Copy link
Member Author

osa1 commented Oct 24, 2025

@rakudrama I can't add you as a reviewer, could you also have a look?

@github-actions
Copy link

Package publishing

Package Version Status Publish tag (post-merge)
package:protobuf 5.1.0-wip WIP (no publish necessary)
package:protoc_plugin 24.0.0 ready to publish protoc_plugin-v24.0.0

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

@osa1
Copy link
Member Author

osa1 commented Oct 30, 2025

With all the branching testing this becomes a quarter long engineering effort.. We need to test all combinations of:

(1) when the iterable is a: PbList, List, and other
(2) when _check is available and not
(3) for all possible error conditions (depends on the method)

Note that error conditions are already not tested today, I wouldn't be surprised if error checking is different based on the check function and argument type today.

I'm inclined to do the simplest possible thing here at the cost of performance. Use a List if you want fast setRange etc. and add your stuff to the message afterwards.

@osa1 osa1 marked this pull request as draft October 30, 2025 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PbList.addAll traverses the iterable twice, causes side effects to run twice

2 participants