Changeset 28536 in webkit


Ignore:
Timestamp:
Dec 7, 2007 2:58:09 PM (16 years ago)
Author:
Darin Adler
Message:

WebCore:

Reviewed by Mitz.

  • bridge/GlobalHistory.h: Change historyContains to take a character pointer plus length instead of requiring a DeprecatedString.
  • bridge/mac/GlobalHistoryMac.mm: (WebCore::historyContains): Updated for above change. Also removes pointless "fast Latin-1" case that was never used.
  • bridge/win/GlobalHistoryWin.cpp: (WebCore::historyContains): Ditto.
  • platform/gtk/TemporaryLinkStubs.cpp: (WebCore::historyContains): Ditto.
  • platform/wx/TemporaryLinkStubs.cpp: (WebCore::historyContains): Ditto.
  • css/CSSStyleSelector.cpp: (WebCore::findHash): Added. Helper for cleanpath. (WebCore::findSlashDotDotSlash): Ditto. (WebCore::findSlashSlash): Ditto. (WebCore::findSlashDotSlash): Ditto. (WebCore::cleanpath): Changed to use fast helper functions instead of slower general-purpose DeprecatedString find function. (WebCore::containsColonSlashSlash): Added. Helper for checkPseudoState. (WebCore::checkPseudoState): Got rid of reference count churn by using an AtomicString* instead of an AtomicString for the attribute value. Changed to use fast helper function instead of slower DeprecatedString::contains function, and also made the fast case not bother allocating a DeprecatedConstString.
  • unrelated tiny cleanup
  • platform/graphics/svg/cg/SVGPaintServerGradientCg.cpp: (WebCore::releaseCachedStops): Use static_cast instead of reinterpret_cast. (WebCore::cgGradientCallback): Ditto.

WebKit/mac:

Reviewed by Mitz.

  • History/WebHistory.mm: Removed unused Latin-1 code path. (-[_WebCoreHistoryProvider containsURL:length:]): Updated for method name change.

WebKit/win:

Reviewed by Mitz.

  • WebHistory.cpp: Removed unused Latin-1 code path. (_WebCoreHistoryProvider::containsItem): Updated for function name change.
Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r28535 r28536  
     12007-12-07  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Mitz.
     4
     5        - http://bugs.webkit.org/show_bug.cgi?id=15981
     6          speed up visited-link code a bit
     7
     8        * bridge/GlobalHistory.h: Change historyContains to take a character pointer plus length
     9        instead of requiring a DeprecatedString.
     10
     11        * bridge/mac/GlobalHistoryMac.mm: (WebCore::historyContains): Updated for above change.
     12        Also removes pointless "fast Latin-1" case that was never used.
     13        * bridge/win/GlobalHistoryWin.cpp: (WebCore::historyContains): Ditto.
     14        * platform/gtk/TemporaryLinkStubs.cpp: (WebCore::historyContains): Ditto.
     15        * platform/wx/TemporaryLinkStubs.cpp: (WebCore::historyContains): Ditto.
     16
     17        * css/CSSStyleSelector.cpp:
     18        (WebCore::findHash): Added. Helper for cleanpath.
     19        (WebCore::findSlashDotDotSlash): Ditto.
     20        (WebCore::findSlashSlash): Ditto.
     21        (WebCore::findSlashDotSlash): Ditto.
     22        (WebCore::cleanpath): Changed to use fast helper functions instead of slower general-purpose
     23        DeprecatedString find function.
     24        (WebCore::containsColonSlashSlash): Added. Helper for checkPseudoState.
     25        (WebCore::checkPseudoState): Got rid of reference count churn by using an AtomicString*
     26        instead of an AtomicString for the attribute value. Changed to use fast helper function
     27        instead of slower DeprecatedString::contains function, and also made the fast case not
     28        bother allocating a DeprecatedConstString.
     29
     30        - unrelated tiny cleanup
     31
     32        * platform/graphics/svg/cg/SVGPaintServerGradientCg.cpp:
     33        (WebCore::releaseCachedStops): Use static_cast instead of reinterpret_cast.
     34        (WebCore::cgGradientCallback): Ditto.
     35
    1362007-12-07  Darin Adler  <darin@apple.com>
    237
  • trunk/WebCore/bridge/GlobalHistory.h

    r23584 r28536  
    11/*
    2  * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
     2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2727#define GlobalHistory_h
    2828
     29#include <wtf/unicode/Unicode.h>
     30
    2931namespace WebCore {
    3032
    31     class DeprecatedString;
    32 
    33     bool historyContains(const DeprecatedString&);
     33    bool historyContains(const UChar* characters, unsigned length);
    3434
    3535} // namespace WebCore
  • trunk/WebCore/bridge/mac/GlobalHistoryMac.mm

    r23584 r28536  
    2727#import "GlobalHistory.h"
    2828
    29 #import "DeprecatedString.h"
    3029#import "WebCoreHistory.h"
    3130
    3231namespace WebCore {
    3332
    34 bool historyContains(const DeprecatedString& s)
     33bool historyContains(const UChar* characters, unsigned length)
    3534{
    3635    // the other side of the bridge is careful not to throw exceptions here
    37     if (s.hasFastLatin1())
    38         return [[WebCoreHistory historyProvider] containsItemForURLLatin1:s.latin1() length:s.length()];
    39     return [[WebCoreHistory historyProvider] containsItemForURLUnicode:(UniChar *)s.unicode() length:s.length()];
     36    return [[WebCoreHistory historyProvider] containsURL:characters length:length];
    4037}
    4138
  • trunk/WebCore/bridge/win/GlobalHistoryWin.cpp

    r23584 r28536  
    2727#include "GlobalHistory.h"
    2828
    29 #include "DeprecatedString.h"
    3029#include "WebCoreHistory.h"
    3130
    3231namespace WebCore {
    3332
    34 bool historyContains(const DeprecatedString& s)
     33bool historyContains(const UChar* characters, unsigned length)
    3534{
    36     if (!WebCoreHistory::historyProvider())
    37         return false;
    38 
    39     // the other side of the bridge is careful not to throw exceptions here
    40     if (s.hasFastLatin1())
    41         return WebCoreHistory::historyProvider()->containsItemForURLLatin1(s.latin1(), s.length());
    42     return WebCoreHistory::historyProvider()->containsItemForURLUnicode((UChar*)s.unicode(), s.length());
     35    WebCoreHistoryProvider* provider = WebCoreHistory::historyProvider();
     36    return provider && provider->containsItemForURLUnicode(characters, length);
    4337}
    4438
  • trunk/WebCore/css/CSSStyleSelector.cpp

    r28357 r28536  
    1 /**
    2  * This file is part of the CSS implementation for KDE.
    3  *
     1/*
    42 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
    53 *           (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
     
    570568}
    571569
    572 // modified version of the one in kurl.cpp
    573 static void cleanpath(DeprecatedString &path)
     570static int findHash(const DeprecatedString& string)
     571{
     572    const ::UChar* ptr = reinterpret_cast<const ::UChar*>(string.unicode());
     573    unsigned length = string.length();
     574    for (unsigned i = 0; i < length; ++i) {
     575        if (ptr[i] == '#')
     576            return i;
     577    }
     578    return -1;
     579}
     580
     581static inline int findSlashDotDotSlash(const DeprecatedString& string)
     582{
     583    const ::UChar* ptr = reinterpret_cast<const ::UChar*>(string.unicode());
     584    unsigned length = string.length();
     585    unsigned loopLimit = length < 4 ? 0 : length - 3;
     586    for (unsigned i = 0; i < loopLimit; ++i) {
     587        if (ptr[i] == '/' && ptr[i + 1] == '.' && ptr[i + 2] == '.' && ptr[i + 3] == '/')
     588            return i;
     589    }
     590    return -1;
     591}
     592
     593static inline int findSlashSlash(const DeprecatedString& string, int position)
     594{
     595    const ::UChar* ptr = reinterpret_cast<const ::UChar*>(string.unicode());
     596    unsigned length = string.length();
     597    unsigned loopLimit = length < 2 ? 0 : length - 1;
     598    for (unsigned i = position; i < loopLimit; ++i) {
     599        if (ptr[i] == '/' && ptr[i + 1] == '/')
     600            return i;
     601    }
     602    return -1;
     603}
     604
     605static inline int findSlashDotSlash(const DeprecatedString& string)
     606{
     607    const ::UChar* ptr = reinterpret_cast<const ::UChar*>(string.unicode());
     608    unsigned length = string.length();
     609    unsigned loopLimit = length < 3 ? 0 : length - 2;
     610    for (unsigned i = 0; i < loopLimit; ++i) {
     611        if (ptr[i] == '/' && ptr[i + 1] == '.' && ptr[i + 2] == '/')
     612            return i;
     613    }
     614    return -1;
     615}
     616
     617static void cleanpath(DeprecatedString& path)
    574618{
    575619    int pos;
    576     while ((pos = path.find("/../")) != -1) {
     620
     621    while ((pos = findSlashDotDotSlash(path)) != -1) {
    577622        int prev = 0;
    578623        if (pos > 0)
    579             prev = path.findRev("/", pos -1);
     624            prev = path.findRev("/", pos - 1);
    580625        // don't remove the host, i.e. http://foo.org/../foo.html
    581         if (prev < 0 || (prev > 3 && path.findRev("://", prev-1) == prev-2))
     626        if (prev < 0 || (prev > 3 && path.findRev("://", prev - 1) == prev - 2))
    582627            path.remove(pos, 3);
    583628        else
    584629            // matching directory found ?
    585             path.remove(prev, pos- prev + 3);
    586     }
    587     pos = 0;
    588    
     630            path.remove(prev, pos - prev + 3);
     631    }
     632
    589633    // Don't remove "//" from an anchor identifier. -rjw
    590634    // Set refPos to -2 to mean "I haven't looked for the anchor yet".
    591635    // We don't want to waste a function call on the search for the the anchor
    592636    // in the vast majority of cases where there is no "//" in the path.
     637    pos = 0;
    593638    int refPos = -2;
    594     while ((pos = path.find("//", pos)) != -1) {
     639    while ((pos = findSlashSlash(path, pos)) != -1) {
    595640        if (refPos == -2)
    596             refPos = path.find("#");
     641            refPos = findHash(path);
    597642        if (refPos > 0 && pos >= refPos)
    598643            break;
    599644       
    600         if (pos == 0 || path[pos-1] != ':')
     645        if (pos == 0 || path[pos - 1] != ':')
    601646            path.remove(pos, 1);
    602647        else
    603648            pos += 2;
    604649    }
    605     while ((pos = path.find("/./")) != -1)
     650
     651    // FIXME: We don't want to remove "/./" from an anchor identifier either.
     652    while ((pos = findSlashDotSlash(path)) != -1)
    606653        path.remove(pos, 2);
     654}
     655
     656static inline bool containsColonSlashSlash(const UChar* characters, unsigned length)
     657{
     658    unsigned loopLimit = length < 3 ? 0 : length - 2;
     659    for (unsigned i = 0; i < loopLimit; ++i)
     660        if (characters[i] == ':' && characters[i + 1] == '/' && characters[i + 2] == '/')
     661            return true;
     662    return false;
    607663}
    608664
     
    613669        return;
    614670    }
    615    
    616     AtomicString attr;
     671
     672    const AtomicString* attr;
    617673    if (e->isHTMLElement())
    618         attr = e->getAttribute(hrefAttr);
     674        attr = &e->getAttribute(hrefAttr);
    619675#if ENABLE(SVG)
    620676    else if (e->isSVGElement())
    621         attr = e->getAttribute(XLinkNames::hrefAttr);
     677        attr = &e->getAttribute(XLinkNames::hrefAttr);
    622678#endif
    623     if (attr.isNull()) {
     679    else {
    624680        pseudoState = PseudoNone;
    625681        return;
    626682    }
    627    
     683
     684    if (attr->isNull()) {
     685        pseudoState = PseudoNone;
     686        return;
     687    }
     688
    628689    if (!checkVisited) {
    629690        pseudoState = PseudoAnyLink;
    630691        return;
    631692    }
    632    
    633     DeprecatedConstString cu(reinterpret_cast<const DeprecatedChar*>(attr.characters()), attr.length());
     693
     694    const UChar* characters = attr->characters();
     695    unsigned length = attr->length();
     696
     697    if (containsColonSlashSlash(characters, length)) {
     698        // FIXME: Strange to not clean the path just beacause it has "://" in it.
     699        pseudoState = historyContains(characters, length) ? PseudoVisited : PseudoLink;
     700        return;
     701    }
     702
     703    DeprecatedConstString cu(reinterpret_cast<const DeprecatedChar*>(characters), length);
    634704    DeprecatedString u = cu.string();
    635     if (!u.contains("://")) {
    636         if (u[0] == '/')
    637             u.prepend(currentEncodedURL->host);
    638         else if (u[0] == '#')
    639             u.prepend(currentEncodedURL->file);
    640         else
    641             u.prepend(currentEncodedURL->path);
    642         cleanpath(u);
    643     }
    644     pseudoState = historyContains(u) ? PseudoVisited : PseudoLink;
     705    if (length && characters[0] == '/')
     706        u.prepend(currentEncodedURL->host);
     707    else if (length && characters[0] == '#')
     708        u.prepend(currentEncodedURL->file);
     709    else
     710        u.prepend(currentEncodedURL->path);
     711    cleanpath(u);
     712    pseudoState = historyContains(reinterpret_cast<const UChar*>(u.unicode()), u.length())
     713        ? PseudoVisited : PseudoLink;
    645714}
    646715
  • trunk/WebCore/platform/graphics/win/FontWin.cpp

    r28298 r28536  
    5050
    5151    const FontPlatformData& platformData = font->platformData();
    52     //NSFont* drawFont;
    53     //if ([gContext isDrawingToScreen]) {
    54     //    drawFont = [platformData.font screenFont];
    55     //    if (drawFont != platformData.font)
    56     //        // We are getting this in too many places (3406411); use ERROR so it only prints on debug versions for now. (We should debug this also, eventually).
    57     //        LOG_ERROR("Attempting to set non-screen font (%@) when drawing to screen.  Using screen font anyway, may result in incorrect metrics.",
    58     //            [[[platformData.font fontDescriptor] fontAttributes] objectForKey:NSFontNameAttribute]);
    59     //} else {
    60     //    drawFont = [platformData.font printerFont];
    61     //    if (drawFont != platformData.font)
    62     //        NSLog(@"Attempting to set non-printer font (%@) when printing.  Using printer font anyway, may result in incorrect metrics.",
    63     //            [[[platformData.font fontDescriptor] fontAttributes] objectForKey:NSFontNameAttribute]);
    64     //}
    6552
    6653    CGContextSetFont(cgContext, platformData.cgFont());
     
    8370    CGContextSetTextMatrix(cgContext, matrix);
    8471
    85     //wkSetCGFontRenderingMode(cgContext, drawFont);
    8672    CGContextSetFontSize(cgContext, platformData.size());
    8773    CGContextSetTextPosition(cgContext, point.x(), point.y());
  • trunk/WebCore/platform/gtk/TemporaryLinkStubs.cpp

    r28426 r28536  
    5757/********************************************************/
    5858
    59 bool WebCore::historyContains(DeprecatedString const&) { return false; }
     59bool WebCore::historyContains(const UChar*, unsigned) { return false; }
    6060
    6161PluginInfo* PlugInInfoStore::createPluginInfoForPluginAtIndex(unsigned) { notImplemented(); return 0;}
  • trunk/WebCore/platform/mac/WebCoreHistory.h

    r15438 r28536  
    11/*
    2  * Copyright (C) 2003 Apple Computer, Inc. All rights reserved.
     2 * Copyright (C) 2003, 2007 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2525
    2626@protocol WebCoreHistoryProvider <NSObject>
    27 - (BOOL)containsItemForURLLatin1:(const char *)latin1 length:(unsigned)length;
    28 - (BOOL)containsItemForURLUnicode:(const UniChar *)unicode length:(unsigned)length;
     27- (BOOL)containsURL:(const UniChar*)unicode length:(unsigned)length;
    2928@end
    3029
    3130@interface WebCoreHistory : NSObject
    32 {
    33 }
    3431
    3532+ (void)setHistoryProvider:(id<WebCoreHistoryProvider>)h;
  • trunk/WebCore/platform/win/WebCoreHistory.h

    r23462 r28536  
    11/*
    2 * Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
     2* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
    33*
    44* Redistribution and use in source and binary forms, with or without
     
    3333class WebCoreHistoryProvider {
    3434public:
    35     virtual bool containsItemForURLLatin1(const char* latin1, unsigned int length) = 0;
    36     virtual bool containsItemForURLUnicode(const UChar* unicode, unsigned int length) = 0;
     35    virtual bool containsURL(const UChar* unicode, unsigned length) = 0;
    3736};
    3837
    3938class WebCoreHistory {
    4039public:
    41     static void setHistoryProvider(WebCoreHistoryProvider* h);
     40    static void setHistoryProvider(WebCoreHistoryProvider*);
    4241    static WebCoreHistoryProvider* historyProvider();
    4342};
  • trunk/WebCore/platform/wx/TemporaryLinkStubs.cpp

    r28480 r28536  
    113113
    114114namespace WebCore {
    115     bool historyContains(DeprecatedString const&) { return false; }
     115    bool historyContains(const UChar*, unsigned) { return false; }
    116116}
    117117
  • trunk/WebCore/svg/graphics/cg/SVGPaintServerGradientCg.cpp

    r27781 r28536  
    4343static void releaseCachedStops(void* info)
    4444{
    45     reinterpret_cast<SVGPaintServerGradient::SharedStopCache*>(info)->deref();
     45    static_cast<SVGPaintServerGradient::SharedStopCache*>(info)->deref();
    4646}
    4747
    4848static void cgGradientCallback(void* info, const CGFloat* inValues, CGFloat* outColor)
    4949{
    50     SVGPaintServerGradient::SharedStopCache* stopsCache = reinterpret_cast<SVGPaintServerGradient::SharedStopCache*>(info);
     50    SVGPaintServerGradient::SharedStopCache* stopsCache = static_cast<SVGPaintServerGradient::SharedStopCache*>(info);
    5151   
    5252    SVGPaintServerGradient::QuartzGradientStop* stops = stopsCache->m_stops.data();
  • trunk/WebKit/mac/ChangeLog

    r28527 r28536  
     12007-12-07  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Mitz.
     4
     5        - http://bugs.webkit.org/show_bug.cgi?id=15981
     6          speed up visited-link code a bit
     7
     8        * History/WebHistory.mm: Removed unused Latin-1 code path.
     9        (-[_WebCoreHistoryProvider containsURL:length:]): Updated for method name change.
     10
    1112007-12-07  Geoffrey Garen  <ggaren@apple.com>
    212
  • trunk/WebKit/mac/History/WebHistory.mm

    r26776 r28536  
    4040#import <wtf/Vector.h>
    4141
    42 
    4342NSString *WebHistoryItemsAddedNotification = @"WebHistoryItemsAddedNotification";
    4443NSString *WebHistoryItemsRemovedNotification = @"WebHistoryItemsRemovedNotification";
     
    5049
    5150static WebHistory *_sharedHistory = nil;
    52 
    53 
    5451
    5552NSString *FileVersionKey = @"WebHistoryFileVersion";
     
    617614}
    618615
    619 #define BUFFER_SIZE 2048
    620 
    621 - (BOOL)containsItemForURLLatin1:(const char *)latin1 length:(unsigned)length
    622 {
    623     const char *latin1Str = latin1;
    624     char staticStrBuffer[BUFFER_SIZE];
    625     char *strBuffer = NULL;
    626     BOOL needToAddSlash = FALSE;
    627 
    628     if (length >= 6 &&
    629         matchLetter(latin1[0], 'h') &&
    630         matchLetter(latin1[1], 't') &&
    631         matchLetter(latin1[2], 't') &&
    632         matchLetter(latin1[3], 'p') &&
    633         (latin1[4] == ':'
    634          || (matchLetter(latin1[4], 's') && latin1[5] == ':'))) {
    635         int pos = latin1[4] == ':' ? 5 : 6;
    636         // skip possible initial two slashes
    637         if (latin1[pos] == '/' && latin1[pos + 1] == '/') {
    638             pos += 2;
    639         }
    640 
    641         char *nextSlash = strchr(latin1 + pos, '/');
    642         if (nextSlash == NULL) {
    643             needToAddSlash = TRUE;
    644         }
    645     }
    646 
    647     if (needToAddSlash) {
    648         if (length + 1 <= BUFFER_SIZE) {
    649             strBuffer = staticStrBuffer;
    650         } else {
    651             strBuffer = (char*)malloc(length + 2);
    652         }
    653         memcpy(strBuffer, latin1, length + 1);
    654         strBuffer[length] = '/';
    655         strBuffer[length+1] = '\0';
    656         length++;
    657 
    658         latin1Str = strBuffer;
    659     }
    660 
    661     CFStringRef str = CFStringCreateWithCStringNoCopy(NULL, latin1Str, kCFStringEncodingWindowsLatin1, kCFAllocatorNull);
    662     BOOL result = [history containsItemForURLString:(id)str];
    663     CFRelease(str);
    664 
    665     if (strBuffer != staticStrBuffer) {
    666         free(strBuffer);
    667     }
    668 
    669     return result;
    670 }
    671 
    672616#define UNICODE_BUFFER_SIZE 1024
    673617
    674 - (BOOL)containsItemForURLUnicode:(const UniChar *)unicode length:(unsigned)length
     618- (BOOL)containsURL:(const UniChar *)unicode length:(unsigned)length
    675619{
    676620    const UniChar *unicodeStr = unicode;
  • trunk/WebKit/win/ChangeLog

    r28531 r28536  
     12007-12-07  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Mitz.
     4
     5        - http://bugs.webkit.org/show_bug.cgi?id=15981
     6          speed up visited-link code a bit
     7
     8        * WebHistory.cpp: Removed unused Latin-1 code path.
     9        (_WebCoreHistoryProvider::containsItem): Updated for function name change.
     10
    1112007-12-07  Steve Falkenburg  <sfalken@apple.com>
    212
  • trunk/WebKit/win/WebHistory.cpp

    r25139 r28536  
    5353    ~_WebCoreHistoryProvider();
    5454
    55     virtual bool containsItemForURLLatin1(const char* latin1, unsigned int length);
    56     virtual bool containsItemForURLUnicode(const UChar* unicode, unsigned int length);
     55    virtual bool containsItem(const UChar* unicode, unsigned int length);
    5756
    5857private:
     
    893892}
    894893
    895 bool _WebCoreHistoryProvider::containsItemForURLLatin1(const char* latin1, unsigned int length)
    896 {
    897     const int bufferSize = 2048;
    898     const char *latin1Str = latin1;
    899     char staticStrBuffer[bufferSize];
    900     char *strBuffer = 0;
     894bool _WebCoreHistoryProvider::containsItem(const UChar* unicode, unsigned int length)
     895{
     896    const int bufferSize = 1024;
     897    const UChar *unicodeStr = unicode;
     898    UChar staticStrBuffer[bufferSize];
     899    UChar *strBuffer = 0;
    901900    bool needToAddSlash = false;
    902901
    903902    if (length >= 6 &&
    904         matchLetter(latin1[0], 'h') &&
    905         matchLetter(latin1[1], 't') &&
    906         matchLetter(latin1[2], 't') &&
    907         matchLetter(latin1[3], 'p') &&
    908         (latin1[4] == ':'
    909         || (matchLetter(latin1[4], 's') && latin1[5] == ':'))) {
    910             int pos = latin1[4] == ':' ? 5 : 6;
     903        matchUnicodeLetter(unicode[0], 'h') &&
     904        matchUnicodeLetter(unicode[1], 't') &&
     905        matchUnicodeLetter(unicode[2], 't') &&
     906        matchUnicodeLetter(unicode[3], 'p') &&
     907        (unicode[4] == ':'
     908        || (matchUnicodeLetter(unicode[4], 's') && unicode[5] == ':'))) {
     909
     910            unsigned pos = unicode[4] == ':' ? 5 : 6;
     911
    911912            // skip possible initial two slashes
    912             if (latin1[pos] == '/' && latin1[pos + 1] == '/') {
     913            if (pos + 1 < length && unicode[pos] == '/' && unicode[pos + 1] == '/')
    913914                pos += 2;
    914             }
    915 
    916             const char* nextSlash = strchr(latin1 + pos, '/');
    917             if (!nextSlash)
     915
     916            while (pos < length && unicode[pos] != '/')
     917                pos++;
     918
     919            if (pos == length)
    918920                needToAddSlash = true;
    919921    }
     
    923925            strBuffer = staticStrBuffer;
    924926        else
    925             strBuffer = (char*)malloc(length + 2);
    926         memcpy(strBuffer, latin1, length + 1);
     927            strBuffer = (UChar*)malloc(sizeof(UChar) * (length + 1));
     928        memcpy(strBuffer, unicode, 2 * length);
    927929        strBuffer[length] = '/';
    928         strBuffer[length+1] = '\0';
    929930        length++;
    930931
    931         latin1Str = strBuffer;
     932        unicodeStr = strBuffer;
    932933    }
    933934
     
    943944        }
    944945    }
    945    
    946     CFStringRef str = CFStringCreateWithCStringNoCopy(NULL, latin1Str, kCFStringEncodingWindowsLatin1, kCFAllocatorNull);
    947     BOOL result = FALSE;
    948     m_historyPrivate->containsItemForURLString((void*)str, &result);
    949     CFRelease(str);
    950 
    951     if (strBuffer != staticStrBuffer)
    952         free(strBuffer);
    953 
    954     return !!result;
    955 }
    956 
    957 bool _WebCoreHistoryProvider::containsItemForURLUnicode(const UChar* unicode, unsigned int length)
    958 {
    959     const int bufferSize = 1024;
    960     const UChar *unicodeStr = unicode;
    961     UChar staticStrBuffer[bufferSize];
    962     UChar *strBuffer = 0;
    963     bool needToAddSlash = false;
    964 
    965     if (length >= 6 &&
    966         matchUnicodeLetter(unicode[0], 'h') &&
    967         matchUnicodeLetter(unicode[1], 't') &&
    968         matchUnicodeLetter(unicode[2], 't') &&
    969         matchUnicodeLetter(unicode[3], 'p') &&
    970         (unicode[4] == ':'
    971         || (matchUnicodeLetter(unicode[4], 's') && unicode[5] == ':'))) {
    972 
    973             unsigned pos = unicode[4] == ':' ? 5 : 6;
    974 
    975             // skip possible initial two slashes
    976             if (pos + 1 < length && unicode[pos] == '/' && unicode[pos + 1] == '/')
    977                 pos += 2;
    978 
    979             while (pos < length && unicode[pos] != '/')
    980                 pos++;
    981 
    982             if (pos == length)
    983                 needToAddSlash = true;
    984     }
    985 
    986     if (needToAddSlash) {
    987         if (length + 1 <= bufferSize)
    988             strBuffer = staticStrBuffer;
    989         else
    990             strBuffer = (UChar*)malloc(sizeof(UChar) * (length + 1));
    991         memcpy(strBuffer, unicode, 2 * length);
    992         strBuffer[length] = '/';
    993         length++;
    994 
    995         unicodeStr = strBuffer;
    996     }
    997 
    998     if (!m_historyPrivate) {
    999         if (SUCCEEDED(m_history->QueryInterface(IID_IWebHistoryPrivate, (void**)&m_historyPrivate))) {
    1000             // don't hold a ref - we're owned by IWebHistory/IWebHistoryPrivate
    1001             m_historyPrivate->Release();
    1002         } else {
    1003             if (strBuffer != staticStrBuffer)
    1004                 free(strBuffer);
    1005             m_historyPrivate = 0;
    1006             return false;
    1007         }
    1008     }
    1009946
    1010947    CFStringRef str = CFStringCreateWithCharactersNoCopy(NULL, (const UniChar*)unicodeStr, length, kCFAllocatorNull);
Note: See TracChangeset for help on using the changeset viewer.