Enhanced string intern API
This commit is contained in:
parent
c660faa5bf
commit
6b6d3dadc2
15
stdx/lexer.d
15
stdx/lexer.d
|
@ -803,17 +803,20 @@ public:
|
||||||
return intern(str, hash);
|
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
|
* Caches a string as above, but uses the given hash code instead of
|
||||||
* calculating one itself. Use this alongside $(LREF hashStep)() can reduce the
|
* calculating one itself. Use this alongside $(LREF hashStep)() can reduce the
|
||||||
* amount of work necessary when lexing dynamic tokens.
|
* amount of work necessary when lexing dynamic tokens.
|
||||||
*/
|
*/
|
||||||
string intern(const(ubyte)[] str, uint hash) pure nothrow @safe
|
string intern(const(ubyte)[] str, uint hash) pure nothrow @safe
|
||||||
in
|
|
||||||
{
|
|
||||||
assert (str.length > 0);
|
|
||||||
}
|
|
||||||
body
|
|
||||||
{
|
{
|
||||||
return _intern(str, hash);
|
return _intern(str, hash);
|
||||||
}
|
}
|
||||||
|
@ -839,6 +842,8 @@ private:
|
||||||
|
|
||||||
string _intern(const(ubyte)[] bytes, uint hash) pure nothrow @trusted
|
string _intern(const(ubyte)[] bytes, uint hash) pure nothrow @trusted
|
||||||
{
|
{
|
||||||
|
if (bytes.length == 0)
|
||||||
|
return "";
|
||||||
import core.atomic;
|
import core.atomic;
|
||||||
import core.memory;
|
import core.memory;
|
||||||
shared ubyte[] mem;
|
shared ubyte[] mem;
|
||||||
|
|
Loading…
Reference in New Issue