Commit f8479433 authored by weinig@apple.com's avatar weinig@apple.com

JavaScriptCore:

        Reviewed by Dan Bernstein.

        - Add a variant of remove that takes a position and a length.

        * wtf/Vector.h:
        (WTF::Vector::remove):

WebCore:

        Reviewed by Dan Bernstein.

        Make the cleanPath function in CSSStyleSelector more efficient by using
        a Vector<UChar>.

        * css/CSSStyleSelector.cpp:
        (WebCore::cleanPath): Make this function work on a Vector<UChar> instead
        of a String.  Also remove unnecessary reverseFind call that could be acomplished
        with two compares.
        (WebCore::checkPseudoState): Remove reserveCapacity calls now that we are using
        a stack buffer.
        * platform/text/PlatformString.h:
        (WebCore::find): Make this find generic enough that it can be used for
        String::find.
        (WebCore::reverseFind): Implement reverseFind so that it can be used
        for with a UChar* and length.
        * platform/text/StringImpl.cpp:
        (WebCore::StringImpl::find): Use implementation in PlatformString.cpp
        (WebCore::StringImpl::reverseFind): Ditto,



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@30593 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent a4d42b5d
2008-02-25 Sam Weinig <sam@webkit.org>
Reviewed by Dan Bernstein.
- Add a variant of remove that takes a position and a length.
* wtf/Vector.h:
(WTF::Vector::remove):
2008-02-25 Mark Mentovai <mark@moxienet.com>
Reviewed by Mark Rowe.
......
......@@ -472,6 +472,7 @@ namespace WTF {
template<typename U, size_t c> void prepend(const Vector<U, c>&);
void remove(size_t position);
void remove(size_t position, size_t length);
void removeLast()
{
......@@ -774,6 +775,18 @@ namespace WTF {
--m_size;
}
template<typename T, size_t inlineCapacity>
inline void Vector<T, inlineCapacity>::remove(size_t position, size_t length)
{
ASSERT(position < size());
ASSERT(position + length < size());
T* beginSpot = begin() + position;
T* endSpot = beginSpot + length;
TypeOperations::destruct(beginSpot, endSpot);
TypeOperations::moveOverlapping(endSpot, end(), beginSpot);
m_size -= length;
}
template<typename T, size_t inlineCapacity>
inline T* Vector<T, inlineCapacity>::releaseBuffer()
{
......
2008-02-25 Sam Weinig <sam@webkit.org>
Reviewed by Dan Bernstein.
Make the cleanPath function in CSSStyleSelector more efficient by using
a Vector<UChar>.
* css/CSSStyleSelector.cpp:
(WebCore::cleanPath): Make this function work on a Vector<UChar> instead
of a String. Also remove unnecessary reverseFind call that could be acomplished
with two compares.
(WebCore::checkPseudoState): Remove reserveCapacity calls now that we are using
a stack buffer.
* platform/text/PlatformString.h:
(WebCore::find): Make this find generic enough that it can be used for
String::find.
(WebCore::reverseFind): Implement reverseFind so that it can be used
for with a UChar* and length.
* platform/text/StringImpl.cpp:
(WebCore::StringImpl::find): Use implementation in PlatformString.cpp
(WebCore::StringImpl::reverseFind): Ditto,
2008-02-26 Satoshi Nakagawa <artension@gmail.com>
Reviewed by Darin. Tweaked and landed by Alexey.
......@@ -607,19 +607,15 @@ static inline bool containsColonSlashSlash(const UChar* characters, unsigned len
return false;
}
static void cleanPath(String& path)
static void cleanPath(Vector<UChar, 512>& path)
{
int pos;
while ((pos = findSlashDotDotSlash(path.characters(), path.length())) != -1) {
int prev = 0;
if (pos > 0)
prev = path.reverseFind("/", pos - 1);
while ((pos = findSlashDotDotSlash(path.data(), path.size())) != -1) {
int prev = reverseFind(path.data(), path.size(), '/', pos - 1);
// don't remove the host, i.e. http://foo.org/../foo.html
if (prev < 0 || (prev > 3 && path.reverseFind("://", prev - 1) == prev - 2))
if (prev < 0 || (prev > 3 && path[prev - 2] == ':' && path[prev - 1] == '/'))
path.remove(pos, 3);
else
// matching directory found ?
path.remove(prev, pos - prev + 3);
}
......@@ -629,20 +625,20 @@ static void cleanPath(String& path)
// in the vast majority of cases where there is no "//" in the path.
pos = 0;
int refPos = -2;
while ((pos = findSlashSlash(path.characters(), path.length(), pos)) != -1) {
while ((pos = findSlashSlash(path.data(), path.size(), pos)) != -1) {
if (refPos == -2)
refPos = find(path.characters(), path.length(), '#');
refPos = find(path.data(), path.size(), '#');
if (refPos > 0 && pos >= refPos)
break;
if (pos == 0 || path[pos - 1] != ':')
path.remove(pos, 1);
path.remove(pos);
else
pos += 2;
}
// FIXME: We don't want to remove "/./" from an anchor identifier either.
while ((pos = findSlashDotSlash(path.characters(), path.length())) != -1)
while ((pos = findSlashDotSlash(path.data(), path.size())) != -1)
path.remove(pos, 2);
}
......@@ -684,22 +680,17 @@ static void checkPseudoState(Element *e, bool checkVisited = true)
return;
}
Vector<UChar> buffer;
Vector<UChar, 512> buffer;
if (length && characters[0] == '/') {
buffer.reserveCapacity(length + currentEncodedURL->prefix.length());
buffer.append(currentEncodedURL->prefix.characters(), currentEncodedURL->prefix.length());
} else if (length && characters[0] == '#') {
buffer.reserveCapacity(length + currentEncodedURL->file.length());
buffer.append(currentEncodedURL->file.characters(), currentEncodedURL->file.length());
} else {
buffer.reserveCapacity(length + currentEncodedURL->path.length());
buffer.append(currentEncodedURL->path.characters(), currentEncodedURL->path.length());
}
buffer.append(characters, length);
String path = String::adopt(buffer);
cleanPath(path);
pseudoState = historyContains(path.characters(), path.length()) ? PseudoVisited : PseudoLink;
cleanPath(buffer);
pseudoState = historyContains(buffer.data(), buffer.size()) ? PseudoVisited : PseudoLink;
}
// a helper function for parsing nth-arguments
......
......@@ -246,7 +246,8 @@ uint64_t charactersToUInt64(const UChar*, size_t, bool* ok = 0); // ignores trai
double charactersToDouble(const UChar*, size_t, bool* ok = 0);
float charactersToFloat(const UChar*, size_t, bool* ok = 0);
int find(const UChar*, size_t, UChar);
int find(const UChar*, size_t, UChar, int startPosition = 0);
int reverseFind(const UChar*, size_t, UChar, int startPosition = -1);
void append(Vector<UChar>&, const String&);
......@@ -265,15 +266,34 @@ inline bool charactersAreAllASCII(const UChar* characters, size_t length)
return !(ored & 0xFF80);
}
inline int find(const UChar* characters, size_t length, UChar character)
inline int find(const UChar* characters, size_t length, UChar character, int startPosition)
{
for (size_t i = 0; i < length; ++i) {
if (startPosition >= static_cast<int>(length))
return -1;
for (size_t i = startPosition; i < length; ++i) {
if (characters[i] == character)
return static_cast<int>(i);
}
return -1;
}
inline int reverseFind(const UChar* characters, size_t length, UChar character, int startPosition)
{
if (startPosition >= static_cast<int>(length) || !length)
return -1;
if (startPosition < 0)
startPosition += length;
while (true) {
if (characters[startPosition] == character)
return startPosition;
if (!startPosition)
return -1;
startPosition--;
}
ASSERT_NOT_REACHED();
return -1;
}
inline void append(Vector<UChar>& vector, const String& string)
{
vector.append(string.characters(), string.length());
......
......@@ -614,15 +614,7 @@ int StringImpl::find(const char* chs, int index, bool caseSensitive)
int StringImpl::find(UChar c, int start)
{
unsigned index = start;
if (index >= m_length )
return -1;
while(index < m_length) {
if (m_data[index] == c)
return index;
index++;
}
return -1;
return WebCore::find(m_data, m_length, c, start);
}
int StringImpl::find(StringImpl* str, int index, bool caseSensitive)
......@@ -683,18 +675,7 @@ int StringImpl::find(StringImpl* str, int index, bool caseSensitive)
int StringImpl::reverseFind(UChar c, int index)
{
if (index >= (int)m_length || m_length == 0)
return -1;
if (index < 0)
index += m_length;
while (1) {
if (m_data[index] == c)
return index;
if (index == 0)
return -1;
index--;
}
return WebCore::reverseFind(m_data, m_length, c, index);
}
int StringImpl::reverseFind(StringImpl* str, int index, bool caseSensitive)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment