diff options
author | special <special@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-12-02 03:53:53 +0000 |
---|---|---|
committer | special <special@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-12-02 03:53:53 +0000 |
commit | 4b0915fc00af7a078f9873de4f5a249adf583eb9 (patch) | |
tree | d4cf9e7550bbc97dfa0ed74ea111259260e79759 | |
parent | 06134cf16bbb2c12be119df105b9b5a9d516b48d (diff) |
I don't know if anything actually uses this, but irc::hex is now *much* more efficient
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5829 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | src/hashcomp.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 27c71defa..45a216e69 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -291,14 +291,19 @@ std::string irc::hex(const unsigned char *raw, size_t rawsz) if (!rawsz) return ""; + /* EWW! This used to be using sprintf, which is WAY inefficient. -Special */ + + const char *hex = "0123456789abcdef"; + char buf[rawsz*2+1]; - size_t i; - for (i = 0; i < rawsz; i++) + size_t i, j; + for (i = 0, j = 0; j < rawsz; ++j) { - sprintf (&(buf[i*2]), "%02x", raw[i]); + buf[i++] = hex[raw[j] / 16]; + buf[i++] = hex[raw[j] % 16]; } - buf[i*2] = 0; + buf[i] = '\0'; return buf; } |