compareQueryValues function

int compareQueryValues(
  1. Object? a,
  2. Object? b
)

Index order of two field values: null first; numbers numerically; strings by UTF-8 bytes; booleans false before true; values of different types by type rank (boolean, number, string, then anything else).

Implementation

int compareQueryValues(Object? a, Object? b) {
  if (a == null && b == null) return 0;
  if (a == null) return -1;
  if (b == null) return 1;
  if (a is num && b is num) return a.compareTo(b);
  if (a is String && b is String) return compareUtf8(a, b);
  if (a is bool && b is bool) {
    return (a ? 1 : 0).compareTo(b ? 1 : 0);
  }
  return _typeRank(a).compareTo(_typeRank(b));
}