Skip to content

_checkNotNull field checks for scalars are not necessary (since null safety) #978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
osa1 opened this issue May 6, 2025 · 0 comments
Open

Comments

@osa1
Copy link
Member

osa1 commented May 6, 2025

Moving this TODO from #959.

I think "check" functions in PbLists can be completely eliminated for the scalars where we only check for nulls:

CheckFunc getCheckFunction(int fieldType) {
switch (fieldType & ~0x7) {
case PbFieldType._BOOL_BIT:
case PbFieldType._BYTES_BIT:
case PbFieldType._STRING_BIT:
case PbFieldType._DOUBLE_BIT:
case PbFieldType._ENUM_BIT:
case PbFieldType._GROUP_BIT:
case PbFieldType._MESSAGE_BIT:
case PbFieldType._INT64_BIT:
case PbFieldType._SINT64_BIT:
case PbFieldType._SFIXED64_BIT:
case PbFieldType._UINT64_BIT:
case PbFieldType._FIXED64_BIT:
// We always use the full range of the same Dart type.
// It's up to the caller to treat the Int64 as signed or unsigned.
// See: https://github.com/google/protobuf.dart/issues/44
return _checkNotNull;
case PbFieldType._FLOAT_BIT:
return _checkFloat;
case PbFieldType._INT32_BIT:
case PbFieldType._SINT32_BIT:
case PbFieldType._SFIXED32_BIT:
return _checkSigned32;
case PbFieldType._UINT32_BIT:
case PbFieldType._FIXED32_BIT:
return _checkUnsigned32;
}
throw ArgumentError('check function not implemented: $fieldType');
}

The generated API for these have non-nullable element type (e.g. PbList<int>) so null checks no longer do anything (since null safety).

@osa1 osa1 changed the title _checkNotNull field checks are not necessary (since null safety) _checkNotNull field checks for scalars are not necessary (since null safety) May 6, 2025
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

No branches or pull requests

1 participant