Index: Source/core/editing/MarkupAccumulator.cpp |
diff --git a/Source/core/editing/MarkupAccumulator.cpp b/Source/core/editing/MarkupAccumulator.cpp |
index 09bd7fe3c4f9ee273823cfee7c14d2c2a73efe6a..ba4b6952e19fb2740c8426727aeaa526cccc91e2 100644 |
--- a/Source/core/editing/MarkupAccumulator.cpp |
+++ b/Source/core/editing/MarkupAccumulator.cpp |
@@ -46,13 +46,37 @@ namespace WebCore { |
using namespace HTMLNames; |
+struct EntityDescription { |
+ UChar entity; |
+ const CString& reference; |
+ EntityMask mask; |
+}; |
+ |
+template <typename CharType> |
+static inline void appendCharactersReplacingEntitiesInternal(StringBuilder& result, CharType* text, unsigned length, const EntityDescription entityMaps[], unsigned entityMapsCount, EntityMask entityMask) |
+{ |
+ unsigned positionAfterLastEntity = 0; |
+ for (unsigned i = 0; i < length; ++i) { |
+ for (unsigned entityIndex = 0; entityIndex < entityMapsCount; ++entityIndex) { |
+ if (text[i] == entityMaps[entityIndex].entity && entityMaps[entityIndex].mask & entityMask) { |
+ result.append(text + positionAfterLastEntity, i - positionAfterLastEntity); |
+ const CString& replacement = entityMaps[entityIndex].reference; |
+ result.append(replacement.data(), replacement.length()); |
+ positionAfterLastEntity = i + 1; |
+ break; |
+ } |
+ } |
+ } |
+ result.append(text + positionAfterLastEntity, length - positionAfterLastEntity); |
+} |
+ |
void MarkupAccumulator::appendCharactersReplacingEntities(StringBuilder& result, const String& source, unsigned offset, unsigned length, EntityMask entityMask) |
{ |
- DEFINE_STATIC_LOCAL(const String, ampReference, ("&")); |
- DEFINE_STATIC_LOCAL(const String, ltReference, ("<")); |
- DEFINE_STATIC_LOCAL(const String, gtReference, (">")); |
- DEFINE_STATIC_LOCAL(const String, quotReference, (""")); |
- DEFINE_STATIC_LOCAL(const String, nbspReference, (" ")); |
+ DEFINE_STATIC_LOCAL(const CString, ampReference, ("&")); |
+ DEFINE_STATIC_LOCAL(const CString, ltReference, ("<")); |
+ DEFINE_STATIC_LOCAL(const CString, gtReference, (">")); |
+ DEFINE_STATIC_LOCAL(const CString, quotReference, (""")); |
+ DEFINE_STATIC_LOCAL(const CString, nbspReference, (" ")); |
static const EntityDescription entityMaps[] = { |
{ '&', ampReference, EntityAmp }, |
@@ -66,38 +90,10 @@ void MarkupAccumulator::appendCharactersReplacingEntities(StringBuilder& result, |
return; |
ASSERT(offset + length <= source.length()); |
- |
- if (source.is8Bit()) { |
- const LChar* text = source.characters8() + offset; |
- |
- size_t positionAfterLastEntity = 0; |
- for (size_t i = 0; i < length; ++i) { |
- for (size_t entityIndex = 0; entityIndex < WTF_ARRAY_LENGTH(entityMaps); ++entityIndex) { |
- if (text[i] == entityMaps[entityIndex].entity && entityMaps[entityIndex].mask & entityMask) { |
- result.append(text + positionAfterLastEntity, i - positionAfterLastEntity); |
- result.append(entityMaps[entityIndex].reference); |
- positionAfterLastEntity = i + 1; |
- break; |
- } |
- } |
- } |
- result.append(text + positionAfterLastEntity, length - positionAfterLastEntity); |
- } else { |
- const UChar* text = source.characters16() + offset; |
- |
- size_t positionAfterLastEntity = 0; |
- for (size_t i = 0; i < length; ++i) { |
- for (size_t entityIndex = 0; entityIndex < WTF_ARRAY_LENGTH(entityMaps); ++entityIndex) { |
- if (text[i] == entityMaps[entityIndex].entity && entityMaps[entityIndex].mask & entityMask) { |
- result.append(text + positionAfterLastEntity, i - positionAfterLastEntity); |
- result.append(entityMaps[entityIndex].reference); |
- positionAfterLastEntity = i + 1; |
- break; |
- } |
- } |
- } |
- result.append(text + positionAfterLastEntity, length - positionAfterLastEntity); |
- } |
+ if (source.is8Bit()) |
+ appendCharactersReplacingEntitiesInternal(result, source.characters8() + offset, length, entityMaps, WTF_ARRAY_LENGTH(entityMaps), entityMask); |
+ else |
+ appendCharactersReplacingEntitiesInternal(result, source.characters16() + offset, length, entityMaps, WTF_ARRAY_LENGTH(entityMaps), entityMask); |
} |
MarkupAccumulator::MarkupAccumulator(Vector<Node*>* nodes, EAbsoluteURLs resolveUrlsMethod, const Range* range) |