toId method

  1. @protected
String? toId(
  1. Object? object,
  2. String groupName
)

Returns a unique id for object that will remain live at least until disposeGroup is called on groupName.

Implementation

@protected
String? toId(Object? object, String groupName) {
  if (object == null) {
    return null;
  }

  final Set<InspectorReferenceData> group = _groups.putIfAbsent(groupName, () => Set<InspectorReferenceData>.identity());
  String? id = _objectToId[object];
  InspectorReferenceData referenceData;
  if (id == null) {
    // TODO(polina-c): comment here why we increase memory footprint by the prefix 'inspector-'.
    // https://github.com/flutter/devtools/issues/5995
    id = 'inspector-$_nextId';
    _nextId += 1;
    _objectToId[object] = id;
    referenceData = InspectorReferenceData(object, id);
    _idToReferenceData[id] = referenceData;
    group.add(referenceData);
  } else {
    referenceData = _idToReferenceData[id]!;
    if (group.add(referenceData)) {
      referenceData.count += 1;
    }
  }
  return id;
}