OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved. |
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 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1086 | 1086 |
1087 // -------- | 1087 // -------- |
1088 | 1088 |
1089 template <typename Strategy> | 1089 template <typename Strategy> |
1090 static String createPlainText(const EphemeralRangeTemplate<Strategy>& range, Tex tIteratorBehaviorFlags behavior) | 1090 static String createPlainText(const EphemeralRangeTemplate<Strategy>& range, Tex tIteratorBehaviorFlags behavior) |
1091 { | 1091 { |
1092 if (range.isNull()) | 1092 if (range.isNull()) |
1093 return emptyString(); | 1093 return emptyString(); |
1094 | 1094 |
1095 TextIteratorAlgorithm<Strategy> it(range.startPosition(), range.endPosition( ), behavior); | 1095 TextIteratorAlgorithm<Strategy> it(range.startPosition(), range.endPosition( ), behavior); |
1096 // The initial buffer size can be critical for performance: https://bugs.web kit.org/show_bug.cgi?id=81192 | |
1097 static const unsigned initialCapacity = 1 << 15; | |
1098 | 1096 |
1099 unsigned bufferLength = 0; | 1097 unsigned bufferLength = 0; |
1100 StringBuilder builder; | 1098 StringBuilder builder; |
1101 builder.reserveCapacity(initialCapacity); | 1099 if (!it.atEnd()) { |
yosin_UTC9
2015/08/26 01:23:21
Can we use early return pattern?
if (it.atEnd())
sof
2015/08/26 06:32:21
That looks better, switched to an early return.
| |
1100 // The initial buffer size can be critical for performance: https://bugs .webkit.org/show_bug.cgi?id=81192 | |
1101 static const unsigned initialCapacity = 1 << 15; | |
1102 | 1102 |
1103 for (; !it.atEnd(); it.advance()) { | 1103 builder.reserveCapacity(initialCapacity); |
1104 it.text().appendTextToStringBuilder(builder); | 1104 |
1105 bufferLength += it.length(); | 1105 for (; !it.atEnd(); it.advance()) { |
1106 it.text().appendTextToStringBuilder(builder); | |
1107 bufferLength += it.length(); | |
yosin_UTC9
2015/08/26 01:23:21
Optional: Do we need to sum result length up?
It s
sof
2015/08/26 06:32:21
Just testing for builder.isEmpty() here would suff
| |
1108 } | |
1106 } | 1109 } |
1107 | 1110 |
1108 if (!bufferLength) | 1111 if (!bufferLength) |
1109 return emptyString(); | 1112 return emptyString(); |
1110 | 1113 |
1111 return builder.toString(); | 1114 return builder.toString(); |
1112 } | 1115 } |
1113 | 1116 |
1114 String plainText(const EphemeralRange& range, TextIteratorBehaviorFlags behavior ) | 1117 String plainText(const EphemeralRange& range, TextIteratorBehaviorFlags behavior ) |
1115 { | 1118 { |
1116 return createPlainText<EditingStrategy>(range, behavior); | 1119 return createPlainText<EditingStrategy>(range, behavior); |
1117 } | 1120 } |
1118 | 1121 |
1119 String plainText(const EphemeralRangeInComposedTree& range, TextIteratorBehavior Flags behavior) | 1122 String plainText(const EphemeralRangeInComposedTree& range, TextIteratorBehavior Flags behavior) |
1120 { | 1123 { |
1121 return createPlainText<EditingInComposedTreeStrategy>(range, behavior); | 1124 return createPlainText<EditingInComposedTreeStrategy>(range, behavior); |
1122 } | 1125 } |
1123 | 1126 |
1124 template class CORE_TEMPLATE_EXPORT TextIteratorAlgorithm<EditingStrategy>; | 1127 template class CORE_TEMPLATE_EXPORT TextIteratorAlgorithm<EditingStrategy>; |
1125 template class CORE_TEMPLATE_EXPORT TextIteratorAlgorithm<EditingInComposedTreeS trategy>; | 1128 template class CORE_TEMPLATE_EXPORT TextIteratorAlgorithm<EditingInComposedTreeS trategy>; |
1126 | 1129 |
1127 } // namespace blink | 1130 } // namespace blink |
OLD | NEW |