Skip to content

content model: Avoid classes.contains, which does extra work like creating a Set #497

@chrisbobbe

Description

@chrisbobbe

Greg and I discovered on our call today that classes.contains does some extra work:

  /// Determine if this element contains the class [value].
  ///
  /// This is the Dart equivalent of jQuery's
  /// [hasClass](http://api.jquery.com/hasClass/).
  @override
  bool contains(Object? value) => readClasses().contains(value);
  @override
  Set<String> readClasses() {
    final s = LinkedHashSet<String>();
    final classname = _element.className;

    for (var name in classname.split(' ')) {
      final trimmed = name.trim();
      if (trimmed.isNotEmpty) {
        s.add(trimmed);
      }
    }
    return s;
  }

When we're checking that there are no classes, we should just check if className is empty. When we're checking that there is one class, we should just do string equality on className. When we're checking that there is more than one class, we might want to do a regular expression or something.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a-contentParsing and rendering Zulip HTML content, notably message contentsperformanceSmooth and responsive UI; fixing jank, stutters, and lag

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions