Use a more useful internal representation for NamespaceableNames #238

Open
opened 2020-08-06 16:57:09 +00:00 by gburd · 0 comments
gburd commented 2020-08-06 16:57:09 +00:00 (Migrated from github.com)

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.

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: ```rust 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.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: greg/mentat#238
No description provided.