Don't iterate iterable arguments twice in PbList (#1070)

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.

To avoid increasing number of cases needed to be tested, we don't special case
iterable types like `PbList` and `List` in these methods. When the check
function is available we simply `map` them with the check function. Otherwise
call the same method on `wrappedList` directly.

Fixes #730.
3 files changed
tree: 52acb2ca244ed0e1122312da58f439a3a3aa7c02
  1. .github/
  2. benchmarks/
  3. protobuf/
  4. protoc_plugin/
  5. tool/
  6. .gitignore
  7. analysis_options.yaml
  8. AUTHORS
  9. LICENSE
  10. pubspec.yaml
  11. README.md
README.md

Protobuf support for Dart

Protocol Buffers (protobuf) are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data.

This repository is home to packages related to protobuf support for Dart.

PackageDescriptionPublished Version
protobufRuntime library for protocol buffers support.pub package
protoc_pluginA protobuf protoc compiler plugin used to generate Dart code.pub package
benchmarksBenchmarks for various protobuf functions.

Publishing automation

For information about our publishing automation and release process, see https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.