Adium

Changeset 24391

Show
Ignore:
Timestamp:
07/17/2008 12:21:34 AM (5 months ago)
Author:
sholt
Message:

Generate even fewer NSStrings:

  • In no case will a string under 4 characters long will be autolinked, we don't need to verify these short substrings.

Also, fixed a link indexing/detection error found by rgov in IRC.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Frameworks/AutoHyperlinks Framework/Source/AHHyperlinkScanner.m

    r24380 r24391  
    4545        static NSCharacterSet   *endSet = nil; 
    4646        static NSCharacterSet   *startSet = nil; 
     47        static NSCharacterSet   *puncSet = nil; 
    4748        static NSCharacterSet   *hostnameComponentSeparatorSet = nil; 
    4849        static NSArray                  *enclosureStartArray = nil; 
     
    123124                 
    124125                if (!endSet) { 
    125                         endSet = [[NSCharacterSet characterSetWithCharactersInString:@"\"',:;>)]}.?!"] retain]; 
     126                        endSet = [[NSCharacterSet characterSetWithCharactersInString:@"\"',:;>)]}.?!@"] retain]; 
    126127                } 
    127128                 
     
    129130                        NSMutableCharacterSet *mutableStartSet = [[NSMutableCharacterSet alloc] init]; 
    130131                        [mutableStartSet formUnionWithCharacterSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 
    131                         [mutableStartSet formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@"\"',:;<.?!-@"]]; 
     132                        [mutableStartSet formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@"\"'.,:;<?!-@"]]; 
    132133                        startSet = [[NSCharacterSet characterSetWithBitmapRepresentation:[mutableStartSet bitmapRepresentation]] retain]; 
    133134                        [mutableStartSet release]; 
     135                } 
     136                 
     137                if (!puncSet) { 
     138                        puncSet = [[NSCharacterSet characterSetWithCharactersInString:@"\"'.,:;<?!"] retain]; 
    134139                } 
    135140                 
     
    250255    // otherwise we end up validating urls that look like this "http://www.adiumx.com/ <--cool" 
    251256        [self _scanString:m_scanString charactersFromSet:startSet intoRange:nil fromIndex:&scannedLocation]; 
    252          
     257 
    253258        // main scanning loop 
    254259        while([self _scanString:m_scanString upToCharactersFromSet:skipSet intoRange:&scannedRange fromIndex:&scannedLocation]) { 
    255260         
    256                 unsigned long _scanLoc = scannedLocation; 
    257                  
    258261                // Check for and filter  enclosures.  We can't add (, [, etc. to the skipSet as they may be in a URI 
    259262                if([enclosureSet characterIsMember:[m_scanString characterAtIndex:scannedRange.location]]){ 
     
    263266                                encRange = [m_scanString rangeOfString:[enclosureStopArray objectAtIndex:encIdx] options:NSBackwardsSearch range:scannedRange]; 
    264267                                if(NSNotFound != encRange.location){ 
    265                                         _scanLoc -= scannedRange.length - encRange.location; 
    266268                                        scannedRange.location++; scannedRange.length -= 2; 
    267269                                } 
     
    282284        // parent string, its validation status (valid, file, degenerate, etc), and its range in the parent string 
    283285                AH_URI_VERIFICATION_STATUS       validStatus; 
    284                 NSString                                        *_scanString = [m_scanString substringWithRange:scannedRange]; 
    285         if(_scanString && [[self class] isStringValidURI:_scanString usingStrict:m_strictChecking fromIndex:&m_scanLocation withStatus:&validStatus]){ 
     286                NSString                                        *_scanString = nil; 
     287                if(3 < scannedRange.length) _scanString = [m_scanString substringWithRange:scannedRange]; 
     288        if((3 < scannedRange.length) && [[self class] isStringValidURI:_scanString usingStrict:m_strictChecking fromIndex:&m_scanLocation withStatus:&validStatus]){ 
    286289            AHMarkedHyperlink   *markedLink; 
    287290                         
     
    324327        } 
    325328 
    326         //step location after scanning a string 
    327                 NSRange startRange = [m_scanString rangeOfCharacterFromSet:startSet options:0 range:scannedRange]; 
    328                 if (startRange.location != NSNotFound) { 
    329                         m_scanLocation += startRange.length; 
    330                         if(m_scanLocation > m_scanStringLength) 
    331                                 m_scanLocation--; 
    332                 }else{ 
     329                //step location after scanning a string 
     330                NSRange startRange = [m_scanString rangeOfCharacterFromSet:puncSet options:NSLiteralSearch range:scannedRange]; 
     331                if (startRange.location != NSNotFound) 
     332                        m_scanLocation = startRange.location + startRange.length; 
     333                else 
    333334                        m_scanLocation += scannedRange.length; 
    334                         if(m_scanLocation > m_scanStringLength) 
    335                                m_scanLocation--; 
    336                 } 
     335                         
     336                if(m_scanLocation > m_scanStringLength) m_scanLocation--; 
     337 
    337338                scannedLocation = m_scanLocation; 
    338339    }