Addressed concerns in <rdar://problem/3803117> RESP: High complexity in icu uidna_ID...
authorrjw <rjw@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Oct 2004 01:32:23 +0000 (01:32 +0000)
committerrjw <rjw@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Oct 2004 01:32:23 +0000 (01:32 +0000)
In practice I saw NO improvement in performance.  Although,
special-case tests could possibly show improvement.  Anyway,
the changes don't hurt performance.

        Reviewed by Maciej.

        * Misc.subproj/WebNSURLExtras.m:
        (-[NSString _web_mapHostNameWithRange:encode:makeString:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@7834 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/ChangeLog
WebKit/Misc.subproj/WebNSURLExtras.m

index 569c56d961b103ef781f0f4b7c2001eb234f0632..045667b8062edad7e1cd5e560b8ab276e38c76be 100644 (file)
@@ -1,3 +1,16 @@
+2004-10-13  Richard Williamson   <rjw@apple.com>
+
+       Addressed concerns in <rdar://problem/3803117> RESP: High complexity in icu uidna_IDNToASCII called by [NSString(WebNSURLExtras) _web_mapHostNameWithRange:encode:makeString:]
+
+       In practice I saw NO improvement in performance.  Although,
+       special-case tests could possibly show improvement.  Anyway,
+       the changes don't hurt performance.
+
+        Reviewed by Maciej.
+
+        * Misc.subproj/WebNSURLExtras.m:
+        (-[NSString _web_mapHostNameWithRange:encode:makeString:]):
+
 2004-10-13  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Ken.
index 61e898b89bae7b9efed0c85cca20ec69f12579f9..da7305a72c32de64abf96aa676a9d429c866fa05 100644 (file)
@@ -727,6 +727,9 @@ static NSString *mapHostNames(NSString *string, BOOL encode)
     if (range.length > HOST_NAME_BUFFER_LENGTH) {
         return nil;
     }
+
+    if ([self length] == 0)
+        return nil;
     
     UChar sourceBuffer[HOST_NAME_BUFFER_LENGTH];
     UChar destinationBuffer[HOST_NAME_BUFFER_LENGTH];
@@ -744,6 +747,13 @@ static NSString *mapHostNames(NSString *string, BOOL encode)
     
     int length = range.length;
     [string getCharacters:sourceBuffer range:range];
+
+    // Avoid expensive calls to uidna_IDNToASCII or uidna_IDNToUnicode for localhost
+    UChar firstChar = sourceBuffer[0];
+    if (firstChar == 'l' || firstChar == 'L') {
+        if ([self rangeOfString:@"localhost" options:NSCaseInsensitiveSearch range:range].location != NSNotFound)
+            return nil;
+    }
     
     UErrorCode error = U_ZERO_ERROR;
     int32_t numCharactersConverted = (encode ? uidna_IDNToASCII : uidna_IDNToUnicode)