From 6b6d3dadc24fa7031f9e173b77eb3d313ea8ee62 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Fri, 28 Feb 2014 15:05:35 -0800 Subject: [PATCH] Enhanced string intern API --- stdx/lexer.d | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/stdx/lexer.d b/stdx/lexer.d index 86eca05..2508d73 100644 --- a/stdx/lexer.d +++ b/stdx/lexer.d @@ -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;