Skip to content

Commit

Permalink
Remove an unnecessary indirection in the binary format. (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmorgan authored Sep 27, 2024
1 parent 98bd197 commit 20c1bf1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
9 changes: 0 additions & 9 deletions pkgs/dart_model/lib/src/json_buffer/json_buffer_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,6 @@ class JsonBufferBuilder {
/// Reads the length at [_Pointer].
_Pointer _readLength(_Pointer pointer) => _readUint32(pointer);

/// Adds [pointer] to the buffer, returns a new [_Pointer] to it.
_Pointer _addPointerTo(_Pointer pointer) {
_explanations?.push('_addPointerToPointer $pointer');
final result = _reserve(_pointerSize);
_writePointer(result, pointer);
_explanations?.pop();
return result;
}

/// Writes [pointerValue] at [pointer].
void _writePointer(_Pointer pointer, _Pointer pointerValue) {
_explanations?.push('_writePointer $pointerValue');
Expand Down
9 changes: 5 additions & 4 deletions pkgs/dart_model/lib/src/json_buffer/typed_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ extension TypedMaps on JsonBufferBuilder {
_pointerSize + (filled ? 0 : schema._fieldSetSize) + valuesSize);

// Write the pointer to schema, setting the high bit if the map is filled.
var schemaPointer = _pointersBySchema[schema] ??=
_addPointerTo(_addClosedMap(schema.toMap()));
var schemaPointer =
_pointersBySchema[schema] ??= _addClosedMap(schema.toMap());

if (filled) schemaPointer |= 0x80000000;
_writePointer(pointer, schemaPointer);

Expand Down Expand Up @@ -264,8 +265,8 @@ class _TypedMap

/// The schema of this "typed map" giving its field names and types.
late final TypedMapSchema _schema =
_buffer._schemasByPointer[_schemaPointer] ??= TypedMapSchema(
_buffer._readClosedMap(_buffer._readPointer(_schemaPointer)).cast());
_buffer._schemasByPointer[_schemaPointer] ??=
TypedMapSchema(_buffer._readClosedMap(_schemaPointer).cast());

/// Whether all fields are present, meaning no explicit field set was written.
late final bool filled = (_buffer._readPointer(_pointer) & 0x80000000) != 0;
Expand Down

0 comments on commit 20c1bf1

Please sign in to comment.