Skip to content

Commit

Permalink
Make protoName unCamelCase lazy (#606)
Browse files Browse the repository at this point in the history
This makes 0.3% improvement in runtime in an internal benchmark.
  • Loading branch information
jiahaog committed Apr 19, 2022
1 parent ded1ac7 commit a0021c7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions protobuf/lib/src/protobuf/field_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ class FieldInfo<T> {
/// ```
/// `protoName` for the `result_per_page` field above is `"result_per_page"`.
/// This will typically consist of words separated with underscores.
final String protoName;
String get protoName {
return _protoName ??= _unCamelCase(name);
}

String? _protoName;

/// Field number as specified in the proto definition. Example:
/// ```proto
Expand Down Expand Up @@ -80,7 +84,7 @@ class FieldInfo<T> {
String? protoName})
: makeDefault = findMakeDefault(type, defaultOrMaker),
check = null,
protoName = protoName ?? _unCamelCase(name),
_protoName = protoName,
assert(type != 0),
assert(!_isGroupOrMessage(type) ||
subBuilder != null ||
Expand All @@ -90,7 +94,7 @@ class FieldInfo<T> {
// Represents a field that has been removed by a program transformation.
FieldInfo.dummy(this.index)
: name = '<removed field>',
protoName = '<removed field>',
_protoName = '<removed field>',
tagNumber = 0,
type = 0,
makeDefault = null,
Expand All @@ -104,7 +108,7 @@ class FieldInfo<T> {
this.check, this.subBuilder,
{this.valueOf, this.enumValues, this.defaultEnumValue, String? protoName})
: makeDefault = (() => PbList<T>(check: check!)),
protoName = protoName ?? _unCamelCase(name) {
_protoName = protoName {
ArgumentError.checkNotNull(name, 'name');
ArgumentError.checkNotNull(tagNumber, 'tagNumber');
assert(_isRepeated(type));
Expand Down

0 comments on commit a0021c7

Please sign in to comment.