Skip to content

Add "associated data" to support namespaces #29

@kmcallister

Description

@kmcallister

The conceptual model for Atom becomes

struct Atom<T = ()> {
    string: String,
    assoc: Option<T>,
}

Any atom where assoc.is_some() is interned in the dynamic table. html5ever and Servo will use this to store namespace and prefix (see #26), with None representing the HTML namespace and an empty prefix. This shrinks a qualified name to a single word, without any performance penalty to HTML names.

One complication is that we need two different notions of equality on this associated data. An XML document can contain nodes which use different prefixes to produce the same qualified name. We can't combine these in the interning table, because it's possible to read the original prefix out of the DOM. But when we're comparing atoms for equality we need to ignore the prefix.

Also, the global interning table needs to be aware of the type T somehow. We could have a set of tables indexed by the type T, hopefully resolving the polymorphism at compile time. (It should really be more like the entire crate is parametrized on T.) In C++ I would use a static member variable in a class template, but I don't know of any analogous mechanism in Rust (I checked and static muts inside generic functions get combined.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions