Source/JavaScriptCore/ChangeLog

 12014-01-12 Darin Adler <darin@apple.com>
 2
 3 Reduce use of String::characters
 4 https://bugs.webkit.org/show_bug.cgi?id=126854
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * API/JSValueRef.cpp:
 9 (JSValueMakeFromJSONString): Use characters16 instead of characters for 16-bit case.
 10 Had to remove length check because an empty string could be either 8 bit or 16 bit.
 11 Don't need a null string check before calling is8Bit because JSStringRef can't hold
 12 a null string.
 13
 14 * bindings/ScriptValue.cpp:
 15 (Deprecated::jsToInspectorValue): Use the existing string here instead of creating
 16 a new one by calling characters and length on the old string. I think this may be
 17 left over from when string types were not the same in JavaScriptCore and WebCore.
 18 Also rewrite the property names loop to use modern for syntax and fewer locals.
 19
 20 * inspector/InspectorValues.cpp:
 21 (Inspector::escapeChar): Changed to use appendLiteral instead of hard-coding string
 22 lengths. Moved handling of "<" and ">" in here instead of at the call site.
 23 (Inspector::doubleQuoteString): Simplify the code so there is no use of characters
 24 and length. This is still an inefficient way of doing this job and could use a rethink.
 25
 26 * runtime/DatePrototype.cpp:
 27 (JSC::formatLocaleDate): Use RetainPtr, createCFString, and the conversion from
 28 CFStringRef to WTF::String to remove a lot of unneeded code.
 29
 30 * runtime/Identifier.h: Removed unneeded Identifier::characters function.
 31
 32 * runtime/JSStringBuilder.h:
 33 (JSC::JSStringBuilder::append): Use characters16 instead of characters function here,
 34 since we have already checked is8Bit above.
 35
1362014-01-12 Andy Estes <aestes@apple.com>
237
338 [iOS] Enable the JSC Objective-C API

Source/WTF/ChangeLog

 12014-01-12 Darin Adler <darin@apple.com>
 2
 3 Reduce use of String::characters
 4 https://bugs.webkit.org/show_bug.cgi?id=126854
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * wtf/text/StringImpl.cpp:
 9 (WTF::StringImpl::replace): Use characters16 here since is8Bit was already checked.
 10 * wtf/text/WTFString.h:
 11 (WTF::String::isAllSpecialCharacters): Use characters16 here since is8Bit was
 12 already checked. Also renamed "len" to "length".
 13
1142014-01-12 Anders Carlsson <andersca@apple.com>
215
316 Replace more uses of AtomicallyInitializedStatic with std::call_once

Source/WebCore/ChangeLog

 12014-01-12 Darin Adler <darin@apple.com>
 2
 3 Reduce use of String::characters
 4 https://bugs.webkit.org/show_bug.cgi?id=126854
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * bindings/objc/WebScriptObject.mm:
 9 (+[WebScriptObject _convertValueToObjcValue:JSC::originRootObject:rootObject:]):
 10 Get rid of unneeded code to turn a WTF::String into an NSString, since that's
 11 built into the WTF::String class.
 12
 13 * editing/CompositeEditCommand.cpp:
 14 (WebCore::containsOnlyWhitespace): Use WTF::String's [] operator instead of
 15 an explicit call to the characters function. Small performance cost.
 16 * editing/TypingCommand.cpp:
 17 (WebCore::TypingCommand::insertText): Ditto.
 18
 19 * editing/VisibleUnits.cpp:
 20 (WebCore::startOfParagraph): Use reverseFind instead of writing our own loop.
 21 (WebCore::endOfParagraph): Use find instead of writing our own loop.
 22
 23 * html/parser/HTMLParserIdioms.cpp:
 24 (WebCore::stripLeadingAndTrailingHTMLSpaces): Use characters16 instead of
 25 characters since we have already checked is8Bit.
 26 (WebCore::parseHTMLNonNegativeInteger): Ditto. Replace the length check with
 27 a check of isNull since a zero length string could be 8 bit, but it's not
 28 safe to call is8Bit on a null WTF::String. (That should probably be fixed.)
 29
 30 * inspector/ContentSearchUtils.cpp:
 31 (WebCore::ContentSearchUtils::createSearchRegexSource): Use StringBuilder
 32 instead of String in code that builds up a string one character at a time.
 33 The old way was ridiculously slow because it allocated a new string for every
 34 character; the new way still isn't all that efficient, but it's better. Also
 35 changed to use strchr instead of WTF::String::find for special characters.
 36
 37 * inspector/InspectorStyleSheet.cpp:
 38 (WebCore::InspectorStyle::newLineAndWhitespaceDelimiters): Use WTF::String's
 39 [] operator instead of an explicit call to the characters function.
 40 * inspector/InspectorStyleTextEditor.cpp:
 41 (WebCore::InspectorStyleTextEditor::insertProperty): Ditto.
 42 (WebCore::InspectorStyleTextEditor::internalReplaceProperty): Ditto.
 43 * platform/Length.cpp:
 44 (WebCore::newCoordsArray): Ditto.
 45
 46 * platform/LinkHash.cpp:
 47 (WebCore::visitedLinkHash): Use characters16 instead of characters since
 48 we have already checked is8Bit. Replace the length check with a check of
 49 isNull (as above in parseHTMLNonNegativeInteger).
 50
 51 * platform/graphics/Color.cpp:
 52 (WebCore::Color::parseHexColor): Use characters16 since we already checked is8Bit.
 53 (WebCore::Color::Color): Ditto.
 54
 55 * platform/graphics/TextRun.h:
 56 (WebCore::TextRun::TextRun): Use characters16 instead of characters since
 57 we have already checked is8Bit. Replace the length check with a check of
 58 isNull (as above in parseHTMLNonNegativeInteger).
 59
 60 * platform/text/TextEncodingRegistry.cpp:
 61 (WebCore::atomicCanonicalTextEncodingName): Use characters16 instead of
 62 characters since we already checked is8Bit. Also use isEmpty instead of !length.
 63
 64 * rendering/RenderBlock.cpp:
 65 (WebCore::RenderBlock::constructTextRun): Use characters16 instead of characters
 66 since we have already checked is8Bit. Replace the length check with a check of
 67 isNull (as above in parseHTMLNonNegativeInteger).
 68
 69 * rendering/RenderCombineText.cpp:
 70 (WebCore::RenderCombineText::width): Check for zero length instead of checking
 71 for null characters.
 72
 73 * svg/SVGFontElement.cpp:
 74 (WebCore::SVGFontElement::registerLigaturesInGlyphCache): Rewrite ligatures
 75 for loop and give local variables a better name. Construct the substring with
 76 the substring function. Still a really inefficient approach -- allocating a new
 77 string for every character is absurdly expensive.
 78
 79 * xml/XPathFunctions.cpp:
 80 (WebCore::XPath::FunId::evaluate): Use String instead of StringBuilder. Still
 81 not all that efficient, but better than before. Use substring to construct the
 82 substring.
 83
 84 * xml/XPathNodeSet.h: Added begin and end functions so we can use a C++11 for
 85 loop with this class.
 86
1872014-01-12 Anders Carlsson <andersca@apple.com>
288
389 Simplify creation of XMLHttpRequestStaticData

Source/JavaScriptCore/API/JSValueRef.cpp

@@JSValueRef JSValueMakeFromJSONString(JSContextRef ctx, JSStringRef string)
323323 APIEntryShim entryShim(exec);
324324 String str = string->string();
325325 unsigned length = str.length();
326  if (length && str.is8Bit()) {
 326 if (str.is8Bit()) {
327327 LiteralParser<LChar> parser(exec, str.characters8(), length, StrictJSON);
328328 return toRef(exec, parser.tryLiteralParse());
329329 }
330  LiteralParser<UChar> parser(exec, str.characters(), length, StrictJSON);
 330 LiteralParser<UChar> parser(exec, str.characters16(), length, StrictJSON);
331331 return toRef(exec, parser.tryLiteralParse());
332332}
333333

Source/JavaScriptCore/bindings/ScriptValue.cpp

@@static PassRefPtr<InspectorValue> jsToInspectorValue(ExecState* scriptState, JSV
115115 return InspectorBasicValue::create(value.asBoolean());
116116 if (value.isNumber())
117117 return InspectorBasicValue::create(value.asNumber());
118  if (value.isString()) {
119  String s = value.getString(scriptState);
120  return InspectorString::create(String(s.characters(), s.length()));
121  }
 118 if (value.isString())
 119 return InspectorString::create(value.getString(scriptState));
122120
123121 if (value.isObject()) {
124122 if (isJSArray(value)) {

@@static PassRefPtr<InspectorValue> jsToInspectorValue(ExecState* scriptState, JSV
138136 JSObject* object = value.getObject();
139137 PropertyNameArray propertyNames(scriptState);
140138 object->methodTable()->getOwnPropertyNames(object, scriptState, propertyNames, ExcludeDontEnumProperties);
141  for (size_t i = 0; i < propertyNames.size(); i++) {
142  const Identifier& name = propertyNames[i];
143  JSValue propertyValue = object->get(scriptState, name);
144  RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, propertyValue, maxDepth);
 139 for (auto& name : propertyNames) {
 140 RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, object->get(scriptState, name), maxDepth);
145141 if (!inspectorValue)
146142 return nullptr;
147  inspectorObject->setValue(String(name.characters(), name.length()), inspectorValue);
 143 inspectorObject->setValue(name.string(), inspectorValue);
148144 }
149145 return inspectorObject;
150146 }

Source/JavaScriptCore/inspector/InspectorValues.cpp

@@PassRefPtr<InspectorValue> buildValue(const UChar* start, const UChar* end, cons
446446
447447inline bool escapeChar(UChar c, StringBuilder* dst)
448448{
 449 // Must escape < and > to prevent script execution.
449450 switch (c) {
450  case '\b': dst->append("\\b", 2); break;
451  case '\f': dst->append("\\f", 2); break;
452  case '\n': dst->append("\\n", 2); break;
453  case '\r': dst->append("\\r", 2); break;
454  case '\t': dst->append("\\t", 2); break;
455  case '\\': dst->append("\\\\", 2); break;
456  case '"': dst->append("\\\"", 2); break;
 451 case '\b': dst->appendLiteral("\\b"); break;
 452 case '\f': dst->appendLiteral("\\f"); break;
 453 case '\n': dst->appendLiteral("\\n"); break;
 454 case '\r': dst->appendLiteral("\\r"); break;
 455 case '\t': dst->appendLiteral("\\t"); break;
 456 case '\\': dst->appendLiteral("\\\\"); break;
 457 case '"': dst->appendLiteral("\\\""); break;
 458 case '<': dst->appendLiteral("\\u003C"); break;
 459 case '>': dst->appendLiteral("\\u003E"); break;
457460 default:
458461 return false;
459462 }

@@inline void doubleQuoteString(const String& str, StringBuilder* dst)
466469 for (unsigned i = 0; i < str.length(); ++i) {
467470 UChar c = str[i];
468471 if (!escapeChar(c, dst)) {
469  if (c < 32 || c > 126 || c == '<' || c == '>') {
470  // 1. Escaping <, > to prevent script execution.
471  // 2. Technically, we could also pass through c > 126 as UTF8, but this
472  // is also optional. It would also be a pain to implement here.
473  unsigned int symbol = static_cast<unsigned int>(c);
474  String symbolCode = String::format("\\u%04X", symbol);
475  dst->append(symbolCode.characters(), symbolCode.length());
476  } else
 472 // We could format c > 126 as UTF-8 instead of escaping them.
 473 if (c >= 32 || c <= 126)
477474 dst->append(c);
 475 else {
 476 // FIXME: Way too slow to do this by creating and destroying a string each time.
 477 dst->append(String::format("\\u%04X", static_cast<unsigned>(c)));
 478 }
478479 }
479480 }
480481 dst->append('"');

Source/JavaScriptCore/runtime/DatePrototype.cpp

@@static JSCell* formatLocaleDate(ExecState* exec, DateInstance*, double timeInMil
162162 else if (format != LocaleDate && !exec->argument(0).isUndefined())
163163 timeStyle = styleFromArgString(arg0String, timeStyle);
164164
165  CFLocaleRef locale = CFLocaleCopyCurrent();
166  CFDateFormatterRef formatter = CFDateFormatterCreate(0, locale, dateStyle, timeStyle);
167  CFRelease(locale);
168 
169  if (useCustomFormat) {
170  CFStringRef customFormatCFString = CFStringCreateWithCharacters(0, customFormatString.characters(), customFormatString.length());
171  CFDateFormatterSetFormat(formatter, customFormatCFString);
172  CFRelease(customFormatCFString);
173  }
174 
175  CFStringRef string = CFDateFormatterCreateStringWithAbsoluteTime(0, formatter, floor(timeInMilliseconds / msPerSecond) - kCFAbsoluteTimeIntervalSince1970);
 165 RetainPtr<CFDateFormatterRef> formatter = adoptCF(CFDateFormatterCreate(kCFAllocatorDefault, adoptCF(CFLocaleCopyCurrent()).get(), dateStyle, timeStyle));
176166
177  CFRelease(formatter);
 167 if (useCustomFormat)
 168 CFDateFormatterSetFormat(formatter.get(), customFormatString.createCFString().get());
178169
179  // We truncate the string returned from CFDateFormatter if it's absurdly long (> 200 characters).
180  // That's not great error handling, but it just won't happen so it doesn't matter.
181  UChar buffer[200];
182  const size_t bufferLength = WTF_ARRAY_LENGTH(buffer);
183  size_t length = CFStringGetLength(string);
184  ASSERT(length <= bufferLength);
185  if (length > bufferLength)
186  length = bufferLength;
187  CFStringGetCharacters(string, CFRangeMake(0, length), buffer);
 170 RetainPtr<CFStringRef> string = adoptCF(CFDateFormatterCreateStringWithAbsoluteTime(kCFAllocatorDefault, formatter.get(), floor(timeInMilliseconds / msPerSecond) - kCFAbsoluteTimeIntervalSince1970));
188171
189  CFRelease(string);
190 
191  return jsNontrivialString(exec, String(buffer, length));
 172 return jsNontrivialString(exec, string.get());
192173}
193174
194175#elif USE(ICU_UNICODE) && !UCONFIG_NO_FORMATTING

Source/JavaScriptCore/runtime/Identifier.h

@@namespace JSC {
5555 const String& string() const { return m_string; }
5656 StringImpl* impl() const { return m_string.impl(); }
5757
58  const UChar* characters() const { return m_string.characters(); }
5958 int length() const { return m_string.length(); }
6059
6160 CString ascii() const { return m_string.ascii(); }

Source/JavaScriptCore/runtime/JSStringBuilder.h

@@public:
105105 }
106106 upConvert();
107107 }
108  m_okay &= buffer16.tryAppend(str.characters(), length);
 108 m_okay &= buffer16.tryAppend(str.characters16(), length);
109109 }
110110
111111 void upConvert()

Source/WTF/wtf/text/StringImpl.cpp

@@PassRef<StringImpl> StringImpl::replace(unsigned position, unsigned lengthToRepl
14891489 for (unsigned i = 0; i < length() - position - lengthToReplace; ++i)
14901490 data[i + position + lengthToInsert] = m_data8[i + position + lengthToReplace];
14911491 } else {
1492  memcpy(data + position + lengthToInsert, characters() + position + lengthToReplace,
 1492 memcpy(data + position + lengthToInsert, characters16() + position + lengthToReplace,
14931493 (length() - position - lengthToReplace) * sizeof(UChar));
14941494 }
14951495 return newImpl;

Source/WTF/wtf/text/WTFString.h

@@inline bool isAllSpecialCharacters(const CharacterType* characters, size_t lengt
624624template<bool isSpecialCharacter(UChar)>
625625inline bool String::isAllSpecialCharacters() const
626626{
627  size_t len = length();
 627 size_t length = this->length();
628628
629  if (!len)
 629 if (!length)
630630 return true;
631631
632632 if (is8Bit())
633  return WTF::isAllSpecialCharacters<isSpecialCharacter, LChar>(characters8(), len);
634  return WTF::isAllSpecialCharacters<isSpecialCharacter, UChar>(characters(), len);
 633 return WTF::isAllSpecialCharacters<isSpecialCharacter>(characters8(), length);
 634 return WTF::isAllSpecialCharacters<isSpecialCharacter>(characters16(), length);
635635}
636636
637637// StringHash is the default hash for String

Source/WebCore/bindings/objc/WebScriptObject.mm

@@+ (id)_convertValueToObjcValue:(JSC::JSValue)value originRootObject:(RootObject*
548548 return [WebScriptObject scriptObjectForJSObject:toRef(object) originRootObject:originRootObject rootObject:rootObject];
549549 }
550550
551  if (value.isString()) {
552  ExecState* exec = rootObject->globalObject()->globalExec();
553  const String& u = asString(value)->value(exec);
554  return [NSString stringWithCharacters:u.characters() length:u.length()];
555  }
 551 if (value.isString())
 552 return asString(value)->value(rootObject->globalObject()->globalExec());
556553
557554 if (value.isNumber())
558555 return [NSNumber numberWithDouble:value.asNumber()];

Source/WebCore/editing/CompositeEditCommand.cpp

@@void CompositeEditCommand::setNodeAttribute(PassRefPtr<Element> element, const Q
667667static inline bool containsOnlyWhitespace(const String& text)
668668{
669669 for (unsigned i = 0; i < text.length(); ++i) {
670  if (!isWhitespace(text.characters()[i]))
 670 if (!isWhitespace(text[i]))
671671 return false;
672672 }
673 
674673 return true;
675674}
676675

Source/WebCore/editing/TypingCommand.cpp

@@void TypingCommand::insertText(Document& document, const String& text, Options o
152152 ASSERT(frame);
153153
154154 if (!text.isEmpty())
155  frame->editor().updateMarkersForWordsAffectedByEditing(isSpaceOrNewline(text.characters()[0]));
 155 frame->editor().updateMarkersForWordsAffectedByEditing(isSpaceOrNewline(text[0]));
156156
157157 insertText(document, text, frame->selection().selection(), options, composition);
158158}

Source/WebCore/editing/VisibleUnits.cpp

@@VisiblePosition startOfParagraph(const VisiblePosition& c, EditingBoundaryCrossi
11461146 ASSERT_WITH_SECURITY_IMPLICATION(n->isTextNode());
11471147 type = Position::PositionIsOffsetInAnchor;
11481148 if (style.preserveNewline()) {
1149  const UChar* chars = toRenderText(r)->characters();
1150  int i = toRenderText(r)->textLength();
1151  int o = offset;
1152  if (n == startNode && o < i)
1153  i = std::max(0, o);
1154  while (--i >= 0) {
1155  if (chars[i] == '\n')
1156  return VisiblePosition(Position(toText(n), i + 1), DOWNSTREAM);
1157  }
 1149 unsigned startOffset = n == startNode ? std::max(0, offset) : std::numeric_limits<unsigned>::max();
 1150 size_t newlineOffset = toRenderText(r)->text()->reverseFind('\n', startOffset);
 1151 if (newlineOffset != notFound)
 1152 return VisiblePosition(Position(toText(n), newlineOffset + 1), DOWNSTREAM);
11581153 }
11591154 node = n;
11601155 offset = 0;

@@VisiblePosition endOfParagraph(const VisiblePosition &c, EditingBoundaryCrossing
12261221 // FIXME: We avoid returning a position where the renderer can't accept the caret.
12271222 if (r->isText() && toRenderText(r)->hasRenderedText()) {
12281223 ASSERT_WITH_SECURITY_IMPLICATION(n->isTextNode());
1229  int length = toRenderText(r)->textLength();
12301224 type = Position::PositionIsOffsetInAnchor;
12311225 if (style.preserveNewline()) {
1232  const UChar* chars = toRenderText(r)->characters();
1233  int o = n == startNode ? offset : 0;
1234  for (int i = o; i < length; ++i) {
1235  if (chars[i] == '\n')
1236  return VisiblePosition(Position(toText(n), i), DOWNSTREAM);
1237  }
 1226 size_t newlineOffset = toRenderText(r)->text()->find('\n', n == startNode ? offset : 0);
 1227 if (newlineOffset != notFound)
 1228 return VisiblePosition(Position(toText(n), newlineOffset), DOWNSTREAM);
12381229 }
12391230 node = n;
12401231 offset = r->caretMaxOffset();

Source/WebCore/html/parser/HTMLParserIdioms.cpp

@@String stripLeadingAndTrailingHTMLSpaces(const String& string)
7171 if (string.is8Bit())
7272 return stripLeadingAndTrailingHTMLSpaces(string, string.characters8(), length);
7373
74  return stripLeadingAndTrailingHTMLSpaces(string, string.characters(), length);
 74 return stripLeadingAndTrailingHTMLSpaces(string, string.characters16(), length);
7575}
7676
7777String serializeForNumberType(const Decimal& number)

@@bool parseHTMLNonNegativeInteger(const String& input, unsigned& value)
267267 // Step 1
268268 // Step 2
269269 unsigned length = input.length();
270  if (length && input.is8Bit()) {
 270 if (input.isNull() || input.is8Bit()) {
271271 const LChar* start = input.characters8();
272272 return parseHTMLNonNegativeIntegerInternal(start, start + length, value);
273273 }
274274
275  const UChar* start = input.characters();
 275 const UChar* start = input.characters16();
276276 return parseHTMLNonNegativeIntegerInternal(start, start + length, value);
277277}
278278

Source/WebCore/inspector/ContentSearchUtils.cpp

3636#include <inspector/InspectorValues.h>
3737#include <wtf/BumpPointerAllocator.h>
3838#include <wtf/StdLibExtras.h>
 39#include <wtf/text/StringBuilder.h>
3940#include <yarr/Yarr.h>
4041
4142using namespace Inspector;

@@static const char regexSpecialCharacters[] = "[](){}+-*.,?\\^$|";
5051
5152static String createSearchRegexSource(const String& text)
5253{
53  String result;
54  const UChar* characters = text.characters();
55  String specials(regexSpecialCharacters);
56 
 54 StringBuilder result;
5755 for (unsigned i = 0; i < text.length(); i++) {
58  if (specials.find(characters[i]) != notFound)
59  result.append("\\");
60  result.append(characters[i]);
 56 if (isASCII(text[i]) && strchr(regexSpecialCharacters, text[i]))
 57 result.append('\\');
 58 result.append(text[i]);
6159 }
62 
63  return result;
 60 return result.toString();
6461}
6562
6663static inline size_t sizetExtractor(const size_t* value)

Source/WebCore/inspector/InspectorStyleSheet.cpp

@@NewLineAndWhitespace& InspectorStyle::newLineAndWhitespaceDelimiters() const
723723 int propertyIndex = 0;
724724 bool isFullPrefixScanned = false;
725725 bool lineFeedTerminated = false;
726  const UChar* characters = text.characters();
727726 while (propertyIndex < propertyCount) {
728727 const WebCore::CSSPropertySourceData& currentProperty = sourcePropertyData->at(propertyIndex++);
729728
730729 bool processNextProperty = false;
731730 int scanEnd = currentProperty.range.start;
732731 for (int i = scanStart; i < scanEnd; ++i) {
733  UChar ch = characters[i];
 732 UChar ch = text[i];
734733 bool isLineFeed = isHTMLLineBreak(ch);
735734 if (isLineFeed) {
736735 if (!lineFeedTerminated)

Source/WebCore/inspector/InspectorStyleTextEditor.cpp

@@void InspectorStyleTextEditor::insertProperty(unsigned index, const String& prop
8282 if (insertLast && !insertFirstInSource) {
8383 propertyStart = styleBodyLength;
8484 if (propertyStart && textToSet.length()) {
85  const UChar* characters = m_styleText.characters();
86 
8785 long curPos = propertyStart - 1; // The last position of style declaration, since propertyStart points past one.
88  while (curPos && isHTMLSpace(characters[curPos]))
 86 while (curPos && isHTMLSpace(m_styleText[curPos]))
8987 --curPos;
90  if (curPos && characters[curPos] != ';') {
 88 if (curPos && m_styleText[curPos] != ';') {
9189 // Prepend a ";" to the property text if appending to a style declaration where
9290 // the last property has no trailing ";".
9391 textToSet.insert(";", 0);

@@void InspectorStyleTextEditor::internalReplaceProperty(const InspectorStylePrope
230228 const SourceRange& range = property.sourceData.range;
231229 long replaceRangeStart = range.start;
232230 long replaceRangeEnd = range.end;
233  const UChar* characters = m_styleText.characters();
234231 long newTextLength = newText.length();
235232 String finalNewText = newText;
236233

@@void InspectorStyleTextEditor::internalReplaceProperty(const InspectorStylePrope
241238 if (replaceRangeStart >= fullPrefixLength && m_styleText.substring(replaceRangeStart - fullPrefixLength, fullPrefixLength) == fullPrefix)
242239 replaceRangeStart -= fullPrefixLength;
243240 } else if (newTextLength) {
244  if (isHTMLLineBreak(newText.characters()[newTextLength - 1])) {
 241 if (isHTMLLineBreak(newText[newTextLength - 1])) {
245242 // Coalesce newlines of the original and new property values (to avoid a lot of blank lines while incrementally applying property values).
246243 bool foundNewline = false;
247244 bool isLastNewline = false;
248245 int i;
249246 int textLength = m_styleText.length();
250  for (i = replaceRangeEnd; i < textLength && isSpaceOrNewline(characters[i]); ++i) {
251  isLastNewline = isHTMLLineBreak(characters[i]);
 247 for (i = replaceRangeEnd; i < textLength && isSpaceOrNewline(m_styleText[i]); ++i) {
 248 isLastNewline = isHTMLLineBreak(m_styleText[i]);
252249 if (isLastNewline)
253250 foundNewline = true;
254251 else if (foundNewline && !isLastNewline) {

Source/WebCore/platform/Length.cpp

@@static int countCharacter(const UChar* data, unsigned length, UChar character)
8888std::unique_ptr<Length[]> newCoordsArray(const String& string, int& len)
8989{
9090 unsigned length = string.length();
91  const UChar* data = string.characters();
9291 StringBuffer<UChar> spacified(length);
9392 for (unsigned i = 0; i < length; i++) {
94  UChar cc = data[i];
 93 UChar cc = string[i];
9594 if (cc > '9' || (cc < '0' && cc != '-' && cc != '*' && cc != '.'))
9695 spacified[i] = ' ';
9796 else

Source/WebCore/platform/LinkHash.cpp

@@static ALWAYS_INLINE LinkHash visitedLinkHashInline(const CharacterType* url, un
214214LinkHash visitedLinkHash(const String& url)
215215{
216216 unsigned length = url.length();
217 
218  if (length && url.is8Bit())
 217 if (url.isNull() || url.is8Bit())
219218 return visitedLinkHashInline(url.characters8(), length);
220  return visitedLinkHashInline(url.characters(), length);
 219 return visitedLinkHashInline(url.characters16(), length);
221220}
222221
223222LinkHash visitedLinkHash(const UChar* url, unsigned length)

Source/WebCore/platform/graphics/Color.cpp

@@bool Color::parseHexColor(const String& name, RGBA32& rgb)
165165 return false;
166166 if (name.is8Bit())
167167 return parseHexColor(name.characters8(), name.length(), rgb);
168  return parseHexColor(name.characters(), name.length(), rgb);
 168 return parseHexColor(name.characters16(), name.length(), rgb);
169169}
170170
171171int differenceSquared(const Color& c1, const Color& c2)

@@Color::Color(const String& name)
182182 if (name.is8Bit())
183183 m_valid = parseHexColor(name.characters8() + 1, name.length() - 1, m_color);
184184 else
185  m_valid = parseHexColor(name.characters() + 1, name.length() - 1, m_color);
 185 m_valid = parseHexColor(name.characters16() + 1, name.length() - 1, m_color);
186186 } else
187187 setNamedColor(name);
188188}

Source/WebCore/platform/graphics/TextRun.h

@@public:
124124 , m_tabSize(0)
125125 {
126126#if ENABLE(8BIT_TEXTRUN)
127  if (m_charactersLength && s.is8Bit()) {
 127 if (s.isNull() || s.is8Bit()) {
128128 m_data.characters8 = s.characters8();
129129 m_is8Bit = true;
130130 } else {
131  m_data.characters16 = s.characters();
 131 m_data.characters16 = s.characters16();
132132 m_is8Bit = false;
133133 }
134134#else

Source/WebCore/platform/text/TextEncodingRegistry.cpp

@@const char* atomicCanonicalTextEncodingName(const CharacterType* characters, siz
343343
344344const char* atomicCanonicalTextEncodingName(const String& alias)
345345{
346  if (!alias.length())
347  return 0;
 346 if (alias.isEmpty())
 347 return nullptr;
348348
349349 if (alias.is8Bit())
350350 return atomicCanonicalTextEncodingName<LChar>(alias.characters8(), alias.length());
351351
352  return atomicCanonicalTextEncodingName<UChar>(alias.characters(), alias.length());
 352 return atomicCanonicalTextEncodingName<UChar>(alias.characters16(), alias.length());
353353}
354354
355355bool noExtendedTextEncodingNameUsed()

Source/WebCore/rendering/RenderBlock.cpp

@@TextRun RenderBlock::constructTextRun(RenderObject* context, const Font& font, c
54795479TextRun RenderBlock::constructTextRun(RenderObject* context, const Font& font, const String& string, const RenderStyle& style, TextRun::ExpansionBehavior expansion, TextRunFlags flags)
54805480{
54815481 unsigned length = string.length();
5482 
54835482#if ENABLE(8BIT_TEXTRUN)
5484  if (length && string.is8Bit())
 5483 if (string.isNull() || string.is8Bit())
54855484 return constructTextRunInternal(context, font, string.characters8(), length, style, expansion, flags);
5486  return constructTextRunInternal(context, font, string.characters(), length, style, expansion, flags);
 5485 return constructTextRunInternal(context, font, string.characters16(), length, style, expansion, flags);
54875486#else
54885487 return constructTextRunInternal(context, font, string.characters(), length, style, expansion, flags);
54895488#endif

Source/WebCore/rendering/RenderCombineText.cpp

@@void RenderCombineText::setTextInternal(const String& text)
6060
6161float RenderCombineText::width(unsigned from, unsigned length, const Font& font, float xPosition, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow* glyphOverflow) const
6262{
63  if (!characters())
 63 if (!textLength())
6464 return 0;
6565
6666 if (m_isCombined)

Source/WebCore/svg/SVGFontElement.cpp

@@void SVGFontElement::registerLigaturesInGlyphCache(Vector<String>& ligatures)
8787 // will not be able to find a glyph for "f", but handles the fallback
8888 // character substitution properly through glyphDataForCharacter().
8989 Vector<SVGGlyph> glyphs;
90  size_t ligaturesSize = ligatures.size();
91  for (size_t i = 0; i < ligaturesSize; ++i) {
92  const String& unicode = ligatures[i];
 90 for (auto& ligature : ligatures) {
 91 unsigned ligatureLength = ligature.length();
 92 ASSERT(ligatureLength > 1);
9393
94  unsigned unicodeLength = unicode.length();
95  ASSERT(unicodeLength > 1);
96 
97  const UChar* characters = unicode.characters();
98  for (unsigned i = 0; i < unicodeLength; ++i) {
99  String lookupString(characters + i, 1);
 94 for (unsigned i = 0; i < ligatureLength; ++i) {
 95 // FIXME: Is there a faster way to do this without allocating/deallocating a string for every character in every ligature?
 96 String lookupString(ligature.substring(i, 1));
10097 m_glyphMap.collectGlyphsForString(lookupString, glyphs);
10198 if (!glyphs.isEmpty()) {
10299 glyphs.clear();

Source/WebCore/xml/XPathFunctions.cpp

@@Value FunPosition::evaluate() const
307307Value FunId::evaluate() const
308308{
309309 Value a = argument(0).evaluate();
310  StringBuilder idList; // A whitespace-separated list of IDs
311310
 311 String idList; // A whitespace-separated list of IDs
312312 if (a.isNodeSet()) {
313  const NodeSet& nodes = a.toNodeSet();
314  for (size_t i = 0; i < nodes.size(); ++i) {
315  String str = stringValue(nodes[i]);
316  idList.append(str);
317  idList.append(' ');
 313 StringBuilder spaceSeparatedList;
 314 for (auto& node : a.toNodeSet()) {
 315 spaceSeparatedList.append(stringValue(node.get()));
 316 spaceSeparatedList.append(' ');
318317 }
 318 idList = spaceSeparatedList.toString();
319319 } else {
320  String str = a.toString();
321  idList.append(str);
 320 idList = a.toString();
322321 }
323322
324323 TreeScope& contextScope = evaluationContext().node->treeScope();

@@Value FunId::evaluate() const
340339
341340 // If there are several nodes with the same id, id() should return the first one.
342341 // In WebKit, getElementById behaves so, too, although its behavior in this case is formally undefined.
343  Node* node = contextScope.getElementById(String(idList.characters() + startPos, endPos - startPos));
 342 Node* node = contextScope.getElementById(idList.substring(startPos, endPos - startPos));
344343 if (node && resultSet.add(node).isNewEntry)
345344 result.append(node);
346345

Source/WebCore/xml/XPathNodeSet.h

@@namespace WebCore {
4444 void reserveCapacity(size_t newCapacity) { m_nodes.reserveCapacity(newCapacity); }
4545 void clear() { m_nodes.clear(); }
4646
 47 Vector<RefPtr<Node>>::const_iterator begin() const { return m_nodes.begin(); }
 48 Vector<RefPtr<Node>>::const_iterator end() const { return m_nodes.end(); }
 49
4750 // NodeSet itself does not verify that nodes in it are unique.
4851 void append(PassRefPtr<Node> node) { m_nodes.append(node); }
4952 void append(const NodeSet& nodeSet) { m_nodes.appendVector(nodeSet.m_nodes); }