writeTypeRef method
Writes a TypeRef
row, returning the corresponding index.
If a TypeRef
with the given namespace
and name
already exists, the
cached index is returned.
Implementation
TypeRefIndex writeTypeRef({required String namespace, required String name}) {
// Return cached reference if it exists.
if (_typeRefs[namespace]?[name] case final typeRef?) return typeRef;
final table = _tableStream[MetadataTableId.typeRef];
final index = TypeRefIndex(table.length);
table.add(
TypeRef(
resolutionScope: ResolutionScope.assemblyRef(
writeAssemblyRef(namespace: namespace),
),
name: _stringHeap.insert(name),
namespace: _stringHeap.insert(namespace),
),
);
_typeRefs
.putIfAbsent(namespace, HashMap.new)
.putIfAbsent(name, () => index);
return index;
}