maskedDiagnosticFields function

Map<String, Object?> maskedDiagnosticFields(
  1. ISpectLogData data,
  2. Iterable<String> keys
)

Masks the captured values under keys in one pass without materializing the whole masked map.

Absent and null fields are omitted from the result.

Implementation

Map<String, Object?> maskedDiagnosticFields(
  ISpectLogData data,
  Iterable<String> keys,
) {
  final captured = data._additionalData;
  if (captured == null) return const <String, Object?>{};
  if (data._masked.ready) {
    final full = data._masked.value;
    if (full == null) return const <String, Object?>{};
    return <String, Object?>{
      for (final key in keys)
        if (full[key] != null) key: full[key],
    };
  }
  final subset = <String, dynamic>{
    for (final key in keys)
      if (captured[key] != null) key: captured[key],
  };
  if (subset.isEmpty) return const <String, Object?>{};
  final mask = data._maskAdditionalData;
  if (mask == null) return subset;
  return mask(subset, data._resourceLimits) ?? const <String, Object?>{};
}