Changeset 928

Show
Ignore:
Timestamp:
12/14/06 21:38:39 (2 years ago)
Author:
ahu
Message:

speed up chopOff operations by doing the chopping manually instead of blah=blah.substr(something)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/pdns/pdns/misc.cc

    r924 r928  
    4242#include "ahuexception.hh" 
    4343#include <sys/types.h> 
    44  
    45  
    4644#include "utility.hh" 
    4745 
     
    9593 
    9694/** Chops off the start of a domain, so goes from 'www.ds9a.nl' to 'ds9a.nl' to 'nl' to ''. Return zero on the empty string */ 
    97 bool chopOff(string &domain) 
     95bool chopOff(string &domain)  
    9896{ 
    9997  if(domain.empty()) 
     
    104102  if(fdot==string::npos)  
    105103    domain=""; 
    106   else  
    107     domain=domain.substr(fdot+1); 
     104  else { 
     105    string::size_type remain = domain.length() - (fdot + 1); 
     106    char tmp[remain]; 
     107    memcpy(tmp, domain.c_str()+fdot+1, remain); 
     108    domain.assign(tmp, remain); // don't dare to do this w/o tmp holder :-) 
     109  } 
    108110  return true; 
    109111} 
     
    121123  if(fdot==domain.size()-1)  
    122124    domain="."; 
    123   else  
    124     domain=domain.substr(fdot+1); 
     125  else  { 
     126    string::size_type remain = domain.length() - (fdot + 1); 
     127    char tmp[remain]; 
     128    memcpy(tmp, domain.c_str()+fdot+1, remain); 
     129    domain.assign(tmp, remain); 
     130  } 
    125131  return true; 
    126132}