Skip to content

Commit 207062b

Browse files
kyungtaewebkit-commit-queue
authored andcommitted
Improve the find word boundary performance
https://bugs.webkit.org/show_bug.cgi?id=125619 In endWordBoundary case, the textBreakPrevious call in findWordBoundary is unnecessary. So use separate function for endWordBoundary can improve the performance. Patch by KyungTae Kim <ktf.kim@samsung.com> on 2013-12-12 Reviewed by Darin Adler. No tests because no operation changes. * editing/VisibleUnits.cpp: Use findEndWordBoundary in endWordBoundary (WebCore::endWordBoundary): * platform/text/TextBoundaries.cpp: Add findEndWordBoundary function (WebCore::findEndWordBoundary): * platform/text/TextBoundaries.h: * platform/text/mac/TextBoundaries.mm: Add findEndWordBoundary function (WebCore::findEndWordBoundary): Canonical link: https://commits.webkit.org/143697@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@160526 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent b7a0302 commit 207062b

5 files changed

Lines changed: 42 additions & 2 deletions

File tree

Source/WebCore/ChangeLog

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
2013-12-12 KyungTae Kim <ktf.kim@samsung.com>
2+
3+
Improve the find word boundary performance
4+
https://bugs.webkit.org/show_bug.cgi?id=125619
5+
6+
In endWordBoundary case, the textBreakPrevious call in findWordBoundary is unnecessary.
7+
So use separate function for endWordBoundary can improve the performance.
8+
9+
Reviewed by Darin Adler.
10+
11+
No tests because no operation changes.
12+
13+
* editing/VisibleUnits.cpp: Use findEndWordBoundary in endWordBoundary
14+
(WebCore::endWordBoundary):
15+
* platform/text/TextBoundaries.cpp: Add findEndWordBoundary function
16+
(WebCore::findEndWordBoundary):
17+
* platform/text/TextBoundaries.h:
18+
* platform/text/mac/TextBoundaries.mm: Add findEndWordBoundary function
19+
(WebCore::findEndWordBoundary):
20+
121
2013-12-12 Benjamin Poulain <bpoulain@apple.com>
222

323
Fix a silly mistake of r160467

Source/WebCore/editing/VisibleUnits.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,8 @@ static unsigned endWordBoundary(const UChar* characters, unsigned length, unsign
650650
return length;
651651
}
652652
needMoreContext = false;
653-
int start, end;
654-
findWordBoundary(characters, length, offset, &start, &end);
653+
int end;
654+
findEndWordBoundary(characters, length, offset, &end);
655655
return end;
656656
}
657657

Source/WebCore/platform/text/TextBoundaries.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ void findWordBoundary(const UChar* chars, int len, int position, int* start, int
9797
*start = textBreakPrevious(it);
9898
}
9999

100+
void findEndWordBoundary(const UChar* chars, int len, int position, int* end)
101+
{
102+
TextBreakIterator* it = wordBreakIterator(chars, len);
103+
*end = textBreakFollowing(it, position);
104+
if (*end < 0)
105+
*end = textBreakLast(it);
106+
}
107+
100108
#endif // !PLATFORM(MAC)
101109

102110
} // namespace WebCore

Source/WebCore/platform/text/TextBoundaries.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ namespace WebCore {
4545
int startOfLastWordBoundaryContext(const UChar* characters, int length);
4646

4747
void findWordBoundary(const UChar*, int len, int position, int* start, int* end);
48+
void findEndWordBoundary(const UChar*, int len, int position, int* end);
4849
int findNextWordFromIndex(const UChar*, int len, int position, bool forward);
4950

5051
}

Source/WebCore/platform/text/mac/TextBoundaries.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ void findWordBoundary(const UChar* chars, int len, int position, int* start, int
4040
*end = range.location + range.length;
4141
}
4242

43+
void findEndWordBoundary(const UChar* chars, int len, int position, int* end)
44+
{
45+
NSString* string = [[NSString alloc] initWithCharactersNoCopy:const_cast<unichar*>(chars)
46+
length:len freeWhenDone:NO];
47+
NSAttributedString* attr = [[NSAttributedString alloc] initWithString:string];
48+
NSRange range = [attr doubleClickAtIndex:(position >= len) ? len - 1 : position];
49+
[attr release];
50+
[string release];
51+
*end = range.location + range.length;
52+
}
53+
4354
int findNextWordFromIndex(const UChar* chars, int len, int position, bool forward)
4455
{
4556
NSString* string = [[NSString alloc] initWithCharactersNoCopy:const_cast<unichar*>(chars)

0 commit comments

Comments
 (0)