Skip to content

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

@osa1

Description

@osa1

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions