From 4b0915fc00af7a078f9873de4f5a249adf583eb9 Mon Sep 17 00:00:00 2001 From: special Date: Sat, 2 Dec 2006 03:53:53 +0000 Subject: 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 --- src/hashcomp.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/hashcomp.cpp') 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; } -- cgit v1.2.3