Show
Ignore:
Timestamp:
06/23/08 00:17:20 (5 years ago)
Author:
ahu
Message:

implement fast wiping of "ds9a.nl" and "blah.ds9a.nl" using inverted ordering

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/packetcache.hh

    r1219 r1220  
    5050*/ 
    5151 
     52struct CIBackwardsStringCompare: public binary_function<string, string, bool>   
     53{ 
     54  bool operator()(const string& a, const string& b) const 
     55  { 
     56    const unsigned char *p1 = (const unsigned char *) a.c_str() + a.length(); 
     57    const unsigned char *p2 = (const unsigned char *) b.c_str() + b.length(); 
     58    int result; 
     59     
     60    if (p1 == p2) { 
     61      return 0; 
     62    } 
     63     
     64    while ((result = dns_tolower (*p1--) - dns_tolower (*p2--)) == 0) 
     65      if (p1 == (unsigned char*)a.c_str() || p2 == (unsigned char*) b.c_str()) 
     66        break; 
     67     
     68    if(result==0) { // one of our strings ended, the shortest one is smaller then 
     69      return a.length() < b.length(); 
     70    } 
     71 
     72    return result < 0; 
     73  } 
     74}; 
     75 
     76 
    5277class PacketCache 
    5378{ 
     
    97122                        member<CacheEntry,bool, &CacheEntry::meritsRecursion> 
    98123                      >, 
    99                   composite_key_compare<CIStringCompare, std::less<uint16_t>, std::less<uint16_t>, std::less<int>, std::less<bool> > 
     124                  composite_key_compare<CIBackwardsStringCompare, std::less<uint16_t>, std::less<uint16_t>, std::less<int>, std::less<bool> > 
    100125                >, 
    101126               sequenced<>