Enhanced string intern API

This commit is contained in:
Hackerpilot 2014-02-28 15:05:35 -08:00
parent c660faa5bf
commit 6b6d3dadc2
1 changed files with 10 additions and 5 deletions

View File

@ -803,17 +803,20 @@ public:
return intern(str, hash);
}
/**
* ditto
*/
string intern(string str) pure nothrow @safe
{
return intern(cast(const(ubyte)[]) str);
}
/**
* Caches a string as above, but uses the given hash code instead of
* calculating one itself. Use this alongside $(LREF hashStep)() can reduce the
* amount of work necessary when lexing dynamic tokens.
*/
string intern(const(ubyte)[] str, uint hash) pure nothrow @safe
in
{
assert (str.length > 0);
}
body
{
return _intern(str, hash);
}
@ -839,6 +842,8 @@ private:
string _intern(const(ubyte)[] bytes, uint hash) pure nothrow @trusted
{
if (bytes.length == 0)
return "";
import core.atomic;
import core.memory;
shared ubyte[] mem;