From ad021b69236bb65860dd075762cd1f73583f9a00 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Tue, 31 May 2022 10:34:02 +0200 Subject: [PATCH] Implemnent dns_tolower() and dns_toupper() by table and fold into dnsname.{cc,hh} Before: 'BurtleHashCI' 0.10 seconds: 66975796.8 runs/s, 0.01 usec/run After: 'BurtleHashCI' 0.10 seconds: 96758136.6 runs/s, 0.01 usec/run --- .not-formatted | 1 - pdns/Makefile.am | 1 - pdns/ascii.hh | 41 -------------------- pdns/dnsdistdist/Makefile.am | 1 - pdns/dnsdistdist/ascii.hh | 1 - pdns/dnsname.cc | 71 +++++++++++++++++++++++++++++++++++ pdns/dnsname.hh | 17 ++++++++- pdns/rcpgenerator.cc | 1 - pdns/recursordist/Makefile.am | 1 - pdns/recursordist/ascii.hh | 1 - pdns/zoneparser-tng.cc | 1 - 11 files changed, 87 insertions(+), 50 deletions(-) delete mode 100644 pdns/ascii.hh delete mode 120000 pdns/dnsdistdist/ascii.hh delete mode 120000 pdns/recursordist/ascii.hh diff --git a/.not-formatted b/.not-formatted index 11b45e5514..22c9a461b4 100644 --- a/.not-formatted +++ b/.not-formatted @@ -6,7 +6,6 @@ ./pdns/anadns.hh ./pdns/arguments.cc ./pdns/arguments.hh -./pdns/ascii.hh ./pdns/auth-caches.cc ./pdns/auth-carbon.cc ./pdns/auth-packetcache.cc diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 3cda451347..06be63a282 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -186,7 +186,6 @@ EXTRA_PROGRAMS = \ pdns_server_SOURCES = \ arguments.cc arguments.hh \ - ascii.hh \ auth-caches.cc auth-caches.hh \ auth-carbon.cc \ auth-packetcache.cc auth-packetcache.hh \ diff --git a/pdns/ascii.hh b/pdns/ascii.hh deleted file mode 100644 index 09f42de6f1..0000000000 --- a/pdns/ascii.hh +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is part of PowerDNS or dnsdist. - * Copyright -- PowerDNS.COM B.V. and its contributors - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * In addition, for the avoidance of any doubt, permission is granted to - * link this program with OpenSSL and to (re)distribute the binaries - * produced as the result of such linking. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#pragma once - -inline bool dns_isspace(char c) -{ - return c==' ' || c=='\t' || c=='\r' || c=='\n'; -} - -inline unsigned char dns_toupper(unsigned char c) -{ - if(c>='a' && c<='z') - c+='A'-'a'; - return c; -} - -inline unsigned char dns_tolower(unsigned char c) -{ - if(c>='A' && c<='Z') - c+='a'-'A'; - return c; -} diff --git a/pdns/dnsdistdist/Makefile.am b/pdns/dnsdistdist/Makefile.am index f7c9e4bafc..e6e04cc596 100644 --- a/pdns/dnsdistdist/Makefile.am +++ b/pdns/dnsdistdist/Makefile.am @@ -123,7 +123,6 @@ dnsdist-web.$(OBJEXT): htmlfiles.h dnsdist-lua-ffi.$(OBJEXT): dnsdist-lua-ffi-interface.inc dnsdist_SOURCES = \ - ascii.hh \ base64.hh \ bpf-filter.cc bpf-filter.hh \ cachecleaner.hh \ diff --git a/pdns/dnsdistdist/ascii.hh b/pdns/dnsdistdist/ascii.hh deleted file mode 120000 index 6d5e3ebf93..0000000000 --- a/pdns/dnsdistdist/ascii.hh +++ /dev/null @@ -1 +0,0 @@ -../ascii.hh \ No newline at end of file diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index 834378586f..31dfa67ef1 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -491,3 +491,74 @@ bool DNSName::has8bitBytes() const return false; } + +// clang-format off +const unsigned char dns_toupper_table[256] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, + 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 'A', 'B', 'C', 'D', 'E', 'F', 'G', + 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + 'X', 'Y', 'Z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, + 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, + 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff +}; + +const unsigned char dns_tolower_table[256] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 'a', 'b', 'c', 'd', 'e', 'f', 'g', + 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', + 'x', 'y', 'z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, + 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, + 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff +}; diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index 6c49d0bd8d..566b3bf7ff 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -36,7 +36,22 @@ #include #endif -#include "ascii.hh" +inline bool dns_isspace(char c) +{ + return c == ' ' || c == '\t' || c == '\r' || c == '\n'; +} + +extern const unsigned char dns_toupper_table[256], dns_tolower_table[256]; + +inline unsigned char dns_toupper(unsigned char c) +{ + return dns_toupper_table[c]; +} + +inline unsigned char dns_tolower(unsigned char c) +{ + return dns_tolower_table[c]; +} uint32_t burtleCI(const unsigned char* k, uint32_t length, uint32_t init); diff --git a/pdns/rcpgenerator.cc b/pdns/rcpgenerator.cc index 9204773d37..3d3dd073ff 100644 --- a/pdns/rcpgenerator.cc +++ b/pdns/rcpgenerator.cc @@ -23,7 +23,6 @@ #include "config.h" #endif #include "rcpgenerator.hh" -#include "ascii.hh" #include "dnsparser.hh" #include "misc.hh" #include "utility.hh" diff --git a/pdns/recursordist/Makefile.am b/pdns/recursordist/Makefile.am index dcf4fb5563..743a17b991 100644 --- a/pdns/recursordist/Makefile.am +++ b/pdns/recursordist/Makefile.am @@ -101,7 +101,6 @@ endif pdns_recursor_SOURCES = \ aggressive_nsec.cc aggressive_nsec.hh \ arguments.cc \ - ascii.hh \ axfr-retriever.hh axfr-retriever.cc \ base32.cc base32.hh \ base64.cc base64.hh \ diff --git a/pdns/recursordist/ascii.hh b/pdns/recursordist/ascii.hh deleted file mode 120000 index 6d5e3ebf93..0000000000 --- a/pdns/recursordist/ascii.hh +++ /dev/null @@ -1 +0,0 @@ -../ascii.hh \ No newline at end of file diff --git a/pdns/zoneparser-tng.cc b/pdns/zoneparser-tng.cc index d9c1594763..f3cdbcb5b9 100644 --- a/pdns/zoneparser-tng.cc +++ b/pdns/zoneparser-tng.cc @@ -22,7 +22,6 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include "ascii.hh" #include "dnsparser.hh" #include "sstuff.hh" #include "misc.hh" -- 2.47.2