qpdb / mentat

A persistent, relational store inspired by Datomic and DataScript.
https://mentat.rs/
Apache License 2.0
52 stars 2 forks source link

Use a more useful internal representation for NamespaceableNames #238

Open gburd opened 4 years ago

gburd commented 4 years ago

After #689 we keep in memory a keyword like :foo/bar as the String "foobar" with boundary = 3.

This is convenient at point of allocation and when comparing name and namespace, but one thing we frequently want to do with keywords is turn them into complete strings for printing, querying, or storage. To do that we end up constructing a new string:

    fn fmt(&self, f: &mut Formatter) -> ::std::fmt::Result {
        if self.0.is_namespaced() {
            let (ns, name) = self.0.components();
            write!(f, ":{}/{}", ns, name)
        } else {
            write!(f, ":{}", self.0.name())
        }
    }

If we were to keep the backing string in this composed format, we'd be able to implement AsRef<str> and print directly from the backing string, at the cost of two more bytes.