OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
3 * Copyright (C) 2005 Alexey Proskuryakov. | 3 * Copyright (C) 2005 Alexey Proskuryakov. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1052 } | 1052 } |
1053 | 1053 |
1054 // ran to the end of the m_textIterator... no more runs left | 1054 // ran to the end of the m_textIterator... no more runs left |
1055 m_atBreak = true; | 1055 m_atBreak = true; |
1056 m_runOffset = 0; | 1056 m_runOffset = 0; |
1057 } | 1057 } |
1058 | 1058 |
1059 String CharacterIterator::string(int numChars) | 1059 String CharacterIterator::string(int numChars) |
1060 { | 1060 { |
1061 Vector<UChar> result; | 1061 Vector<UChar> result; |
1062 result.reserveCapacity(numChars); | 1062 result.reserveInitialCapacity(numChars); |
1063 while (numChars > 0 && !atEnd()) { | 1063 while (numChars > 0 && !atEnd()) { |
1064 int runSize = min(numChars, length()); | 1064 int runSize = min(numChars, length()); |
1065 result.append(characters(), runSize); | 1065 result.append(characters(), runSize); |
1066 numChars -= runSize; | 1066 numChars -= runSize; |
1067 advance(runSize); | 1067 advance(runSize); |
1068 } | 1068 } |
1069 return String::adopt(result); | 1069 return String::adopt(result); |
1070 } | 1070 } |
1071 | 1071 |
1072 static PassRefPtr<Range> characterSubrange(CharacterIterator& it, int offset, in
t length) | 1072 static PassRefPtr<Range> characterSubrange(CharacterIterator& it, int offset, in
t length) |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1220 #endif | 1220 #endif |
1221 } | 1221 } |
1222 | 1222 |
1223 inline SearchBuffer::SearchBuffer(const String& target, bool isCaseSensitive) | 1223 inline SearchBuffer::SearchBuffer(const String& target, bool isCaseSensitive) |
1224 : m_target(target) | 1224 : m_target(target) |
1225 , m_atBreak(true) | 1225 , m_atBreak(true) |
1226 { | 1226 { |
1227 ASSERT(!m_target.isEmpty()); | 1227 ASSERT(!m_target.isEmpty()); |
1228 | 1228 |
1229 size_t targetLength = target.length(); | 1229 size_t targetLength = target.length(); |
1230 m_buffer.reserveCapacity(max(targetLength * 8, minimumSearchBufferSize)); | 1230 m_buffer.reserveInitialCapacity(max(targetLength * 8, minimumSearchBufferSiz
e)); |
1231 m_overlap = m_buffer.capacity() / 4; | 1231 m_overlap = m_buffer.capacity() / 4; |
1232 | 1232 |
1233 // Grab the single global searcher. | 1233 // Grab the single global searcher. |
1234 // If we ever have a reason to do more than once search buffer at once, we'l
l have | 1234 // If we ever have a reason to do more than once search buffer at once, we'l
l have |
1235 // to move to multiple searchers. | 1235 // to move to multiple searchers. |
1236 lockSearcher(); | 1236 lockSearcher(); |
1237 | 1237 |
1238 UStringSearch* searcher = WebCore::searcher(); | 1238 UStringSearch* searcher = WebCore::searcher(); |
1239 UCollator* collator = usearch_getCollator(searcher); | 1239 UCollator* collator = usearch_getCollator(searcher); |
1240 | 1240 |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1537 { | 1537 { |
1538 UChar* result = 0; | 1538 UChar* result = 0; |
1539 | 1539 |
1540 // Do this in pieces to avoid massive reallocations if there is a large amou
nt of text. | 1540 // Do this in pieces to avoid massive reallocations if there is a large amou
nt of text. |
1541 // Use system malloc for buffers since they can consume lots of memory and c
urrent TCMalloc is unable return it back to OS. | 1541 // Use system malloc for buffers since they can consume lots of memory and c
urrent TCMalloc is unable return it back to OS. |
1542 static const unsigned cMaxSegmentSize = 1 << 16; | 1542 static const unsigned cMaxSegmentSize = 1 << 16; |
1543 bufferLength = 0; | 1543 bufferLength = 0; |
1544 typedef pair<UChar*, unsigned> TextSegment; | 1544 typedef pair<UChar*, unsigned> TextSegment; |
1545 Vector<TextSegment>* textSegments = 0; | 1545 Vector<TextSegment>* textSegments = 0; |
1546 Vector<UChar> textBuffer; | 1546 Vector<UChar> textBuffer; |
1547 textBuffer.reserveCapacity(cMaxSegmentSize); | 1547 textBuffer.reserveInitialCapacity(cMaxSegmentSize); |
1548 for (TextIterator it(r); !it.atEnd(); it.advance()) { | 1548 for (TextIterator it(r); !it.atEnd(); it.advance()) { |
1549 if (textBuffer.size() && textBuffer.size() + it.length() > cMaxSegmentSi
ze) { | 1549 if (textBuffer.size() && textBuffer.size() + it.length() > cMaxSegmentSi
ze) { |
1550 UChar* newSegmentBuffer = static_cast<UChar*>(malloc(textBuffer.size
() * sizeof(UChar))); | 1550 UChar* newSegmentBuffer = static_cast<UChar*>(malloc(textBuffer.size
() * sizeof(UChar))); |
1551 if (!newSegmentBuffer) | 1551 if (!newSegmentBuffer) |
1552 goto exit; | 1552 goto exit; |
1553 memcpy(newSegmentBuffer, textBuffer.data(), textBuffer.size() * size
of(UChar)); | 1553 memcpy(newSegmentBuffer, textBuffer.data(), textBuffer.size() * size
of(UChar)); |
1554 if (!textSegments) | 1554 if (!textSegments) |
1555 textSegments = new Vector<TextSegment>; | 1555 textSegments = new Vector<TextSegment>; |
1556 textSegments->append(make_pair(newSegmentBuffer, (unsigned)textBuffe
r.size())); | 1556 textSegments->append(make_pair(newSegmentBuffer, (unsigned)textBuffe
r.size())); |
1557 textBuffer.clear(); | 1557 textBuffer.clear(); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1675 if (!matchLength) | 1675 if (!matchLength) |
1676 return collapsedToBoundary(range, forward); | 1676 return collapsedToBoundary(range, forward); |
1677 } | 1677 } |
1678 | 1678 |
1679 // Then, find the document position of the start and the end of the text. | 1679 // Then, find the document position of the start and the end of the text. |
1680 CharacterIterator computeRangeIterator(range, false, true); | 1680 CharacterIterator computeRangeIterator(range, false, true); |
1681 return characterSubrange(computeRangeIterator, matchStart, matchLength); | 1681 return characterSubrange(computeRangeIterator, matchStart, matchLength); |
1682 } | 1682 } |
1683 | 1683 |
1684 } | 1684 } |
OLD | NEW |