Commit 7324427d authored by darin@apple.com's avatar darin@apple.com

Cut down on use of String::number

https://bugs.webkit.org/show_bug.cgi?id=122382

Reviewed by Anders Carlsson.

Source/JavaScriptCore:

* API/JSCallbackObjectFunctions.h:
(JSC::JSCallbackObject::putByIndex): Use Identifier::from instead of calling
String::number and creating an identifier from that. Can save creating and then
destroying a string if an identifier already exists.
* runtime/Arguments.cpp:
(JSC::Arguments::getOwnPropertySlotByIndex): Ditto.
(JSC::Arguments::getOwnPropertyNames): Ditto.
(JSC::Arguments::putByIndex): Ditto.
* runtime/JSGenericTypedArrayViewInlines.h:
(JSC::::getOwnPropertyNames): Ditto.
* runtime/StringObject.cpp:
(JSC::StringObject::getOwnPropertyNames): Ditto.

Source/WebCore:

* css/CSSGradientValue.cpp:
(WebCore::CSSLinearGradientValue::customCSSText): Use StringBuilder::appendNumber,
instead of creating a string and then appending it.
(WebCore::CSSRadialGradientValue::customCSSText): Ditto.
* css/CSSParser.cpp:
(WebCore::CSSParser::createKeyframe): Ditto.
* editing/DeleteButtonController.cpp:
(WebCore::DeleteButtonController::createDeletionUI): Use ASCII literals instead of
converting numeric constants to strings at runtime with String::number.
(WebCore::DeleteButtonController::show): Ditto.
* svg/SVGNumberList.cpp:
(WebCore::SVGNumberList::valueAsString): Use StringBuilder::appendNumber.
* svg/SVGPointList.cpp:
(WebCore::SVGPointList::valueAsString): Ditto.
* svg/SVGRect.h: Ditto.

Source/WebKit2:

* Shared/mac/RemoteLayerTreeTransaction.mm:
(WebKit::dumpChangedLayers): Use StringBuilder::appendNumber.

Source/WTF:

* wtf/DateMath.cpp:
(WTF::appendTwoDigitNumber): Added. Replaces twoDigitStringFromNumber, which returned a
String and also allocated a temporary string for any number 10 or higher.
(WTF::makeRFC2822DateString): Updated to use the new function.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156964 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2a375b4e
......@@ -279,7 +279,7 @@ void JSCallbackObject<Parent>::putByIndex(JSCell* cell, ExecState* exec, unsigne
JSObjectRef thisRef = toRef(thisObject);
RefPtr<OpaqueJSString> propertyNameRef;
JSValueRef valueRef = toRef(exec, value);
Identifier propertyName = Identifier(exec, String::number(propertyIndex));
Identifier propertyName = Identifier::from(exec, propertyIndex);
for (JSClassRef jsClass = thisObject->classRef(); jsClass; jsClass = jsClass->parentClass) {
if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) {
......
2013-10-05 Darin Adler <darin@apple.com>
Cut down on use of String::number
https://bugs.webkit.org/show_bug.cgi?id=122382
Reviewed by Anders Carlsson.
* API/JSCallbackObjectFunctions.h:
(JSC::JSCallbackObject::putByIndex): Use Identifier::from instead of calling
String::number and creating an identifier from that. Can save creating and then
destroying a string if an identifier already exists.
* runtime/Arguments.cpp:
(JSC::Arguments::getOwnPropertySlotByIndex): Ditto.
(JSC::Arguments::getOwnPropertyNames): Ditto.
(JSC::Arguments::putByIndex): Ditto.
* runtime/JSGenericTypedArrayViewInlines.h:
(JSC::::getOwnPropertyNames): Ditto.
* runtime/StringObject.cpp:
(JSC::StringObject::getOwnPropertyNames): Ditto.
2013-10-04 Mark Lam <mark.lam@apple.com>
Change ScriptDebugServer to use DebuggerCallFrame instead of JavaScriptCallFrame.
......@@ -98,7 +98,7 @@ bool Arguments::getOwnPropertySlotByIndex(JSObject* object, ExecState* exec, uns
return true;
}
return JSObject::getOwnPropertySlot(thisObject, exec, Identifier(exec, String::number(i)), slot);
return JSObject::getOwnPropertySlot(thisObject, exec, Identifier::from(exec, i), slot);
}
void Arguments::createStrictModeCallerIfNecessary(ExecState* exec)
......@@ -160,7 +160,7 @@ void Arguments::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyN
for (unsigned i = 0; i < thisObject->m_numArguments; ++i) {
if (!thisObject->isArgument(i))
continue;
propertyNames.add(Identifier(exec, String::number(i)));
propertyNames.add(Identifier::from(exec, i));
}
if (mode == IncludeDontEnumProperties) {
propertyNames.add(exec->propertyNames().callee);
......@@ -176,7 +176,7 @@ void Arguments::putByIndex(JSCell* cell, ExecState* exec, unsigned i, JSValue va
return;
PutPropertySlot slot(shouldThrow);
JSObject::put(thisObject, exec, Identifier(exec, String::number(i)), value, slot);
JSObject::put(thisObject, exec, Identifier::from(exec, i), value, slot);
}
void Arguments::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
......
......@@ -429,7 +429,7 @@ void JSGenericTypedArrayView<Adaptor>::getOwnPropertyNames(
JSGenericTypedArrayView* thisObject = jsCast<JSGenericTypedArrayView*>(object);
for (unsigned i = 0; i < thisObject->m_length; ++i)
array.add(Identifier(exec, String::number(i)));
array.add(Identifier::from(exec, i));
return Base::getOwnPropertyNames(object, exec, array, mode);
}
......
......@@ -149,7 +149,7 @@ void StringObject::getOwnPropertyNames(JSObject* object, ExecState* exec, Proper
StringObject* thisObject = jsCast<StringObject*>(object);
int size = thisObject->internalValue()->length();
for (int i = 0; i < size; ++i)
propertyNames.add(Identifier(exec, String::number(i)));
propertyNames.add(Identifier::from(exec, i));
if (mode == IncludeDontEnumProperties)
propertyNames.add(exec->propertyNames().length);
return JSObject::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
......
2013-10-05 Darin Adler <darin@apple.com>
Cut down on use of String::number
https://bugs.webkit.org/show_bug.cgi?id=122382
Reviewed by Anders Carlsson.
* wtf/DateMath.cpp:
(WTF::appendTwoDigitNumber): Added. Replaces twoDigitStringFromNumber, which returned a
String and also allocated a temporary string for any number 10 or higher.
(WTF::makeRFC2822DateString): Updated to use the new function.
2013-10-05 Anders Carlsson <andersca@apple.com>
Test the waters and begin using lambdas
......
......@@ -179,12 +179,12 @@ double msToDays(double ms)
return floor(ms / msPerDay);
}
static String twoDigitStringFromNumber(int number)
static void appendTwoDigitNumber(StringBuilder& builder, int number)
{
ASSERT(number >= 0 && number < 100);
if (number > 9)
return String::number(number);
return makeString("0", String::number(number));
ASSERT(number >= 0);
ASSERT(number < 100);
builder.append('0' + number / 10);
builder.append('0' + number % 10);
}
int msToYear(double ms)
......@@ -1096,17 +1096,17 @@ String makeRFC2822DateString(unsigned dayOfWeek, unsigned day, unsigned month, u
stringBuilder.appendNumber(year);
stringBuilder.append(' ');
stringBuilder.append(twoDigitStringFromNumber(hours));
appendTwoDigitNumber(stringBuilder, hours);
stringBuilder.append(':');
stringBuilder.append(twoDigitStringFromNumber(minutes));
appendTwoDigitNumber(stringBuilder, minutes);
stringBuilder.append(':');
stringBuilder.append(twoDigitStringFromNumber(seconds));
appendTwoDigitNumber(stringBuilder, seconds);
stringBuilder.append(' ');
stringBuilder.append(utcOffset > 0 ? '+' : '-');
int absoluteUTCOffset = abs(utcOffset);
stringBuilder.append(twoDigitStringFromNumber(absoluteUTCOffset / 60));
stringBuilder.append(twoDigitStringFromNumber(absoluteUTCOffset % 60));
appendTwoDigitNumber(stringBuilder, absoluteUTCOffset / 60);
appendTwoDigitNumber(stringBuilder, absoluteUTCOffset % 60);
return stringBuilder.toString();
}
......
2013-10-05 Darin Adler <darin@apple.com>
Cut down on use of String::number
https://bugs.webkit.org/show_bug.cgi?id=122382
Reviewed by Anders Carlsson.
* css/CSSGradientValue.cpp:
(WebCore::CSSLinearGradientValue::customCSSText): Use StringBuilder::appendNumber,
instead of creating a string and then appending it.
(WebCore::CSSRadialGradientValue::customCSSText): Ditto.
* css/CSSParser.cpp:
(WebCore::CSSParser::createKeyframe): Ditto.
* editing/DeleteButtonController.cpp:
(WebCore::DeleteButtonController::createDeletionUI): Use ASCII literals instead of
converting numeric constants to strings at runtime with String::number.
(WebCore::DeleteButtonController::show): Ditto.
* svg/SVGNumberList.cpp:
(WebCore::SVGNumberList::valueAsString): Use StringBuilder::appendNumber.
* svg/SVGPointList.cpp:
(WebCore::SVGPointList::valueAsString): Ditto.
* svg/SVGRect.h: Ditto.
2013-10-05 Anders Carlsson <andersca@apple.com>
Test the waters and begin using lambdas
......@@ -492,7 +492,7 @@ String CSSLinearGradientValue::customCSSText() const
result.append(')');
} else {
result.appendLiteral("color-stop(");
result.append(String::number(stop.m_position->getDoubleValue(CSSPrimitiveValue::CSS_NUMBER)));
result.appendNumber(stop.m_position->getDoubleValue(CSSPrimitiveValue::CSS_NUMBER));
result.appendLiteral(", ");
result.append(stop.m_color->cssText());
result.append(')');
......@@ -771,7 +771,7 @@ String CSSRadialGradientValue::customCSSText() const
result.append(')');
} else {
result.appendLiteral("color-stop(");
result.append(String::number(stop.m_position->getDoubleValue(CSSPrimitiveValue::CSS_NUMBER)));
result.appendNumber(stop.m_position->getDoubleValue(CSSPrimitiveValue::CSS_NUMBER));
result.appendLiteral(", ");
result.append(stop.m_color->cssText());
result.append(')');
......
......@@ -11883,7 +11883,7 @@ PassRefPtr<StyleKeyframe> CSSParser::createKeyframe(CSSParserValueList& keys)
}
if (i != 0)
keyString.append(',');
keyString.append(String::number(key));
keyString.appendNumber(key);
keyString.append('%');
}
......
......@@ -224,14 +224,14 @@ void DeleteButtonController::createDeletionUI()
const int borderRadius = 6;
outline->setInlineStyleProperty(CSSPropertyPosition, CSSValueAbsolute);
outline->setInlineStyleProperty(CSSPropertyZIndex, String::number(-1000000));
outline->setInlineStyleProperty(CSSPropertyZIndex, ASCIILiteral("-1000000"));
outline->setInlineStyleProperty(CSSPropertyTop, -borderWidth - m_target->renderBox()->borderTop(), CSSPrimitiveValue::CSS_PX);
outline->setInlineStyleProperty(CSSPropertyRight, -borderWidth - m_target->renderBox()->borderRight(), CSSPrimitiveValue::CSS_PX);
outline->setInlineStyleProperty(CSSPropertyBottom, -borderWidth - m_target->renderBox()->borderBottom(), CSSPrimitiveValue::CSS_PX);
outline->setInlineStyleProperty(CSSPropertyLeft, -borderWidth - m_target->renderBox()->borderLeft(), CSSPrimitiveValue::CSS_PX);
outline->setInlineStyleProperty(CSSPropertyBorderWidth, borderWidth, CSSPrimitiveValue::CSS_PX);
outline->setInlineStyleProperty(CSSPropertyBorderStyle, CSSValueSolid);
outline->setInlineStyleProperty(CSSPropertyBorderColor, "rgba(0, 0, 0, 0.6)");
outline->setInlineStyleProperty(CSSPropertyBorderColor, ASCIILiteral("rgba(0, 0, 0, 0.6)"));
outline->setInlineStyleProperty(CSSPropertyBorderRadius, borderRadius, CSSPrimitiveValue::CSS_PX);
outline->setInlineStyleProperty(CSSPropertyVisibility, CSSValueVisible);
......@@ -249,7 +249,7 @@ void DeleteButtonController::createDeletionUI()
const int buttonBottomShadowOffset = 2;
button->setInlineStyleProperty(CSSPropertyPosition, CSSValueAbsolute);
button->setInlineStyleProperty(CSSPropertyZIndex, String::number(1000000));
button->setInlineStyleProperty(CSSPropertyZIndex, ASCIILiteral("1000000"));
button->setInlineStyleProperty(CSSPropertyTop, (-buttonHeight / 2) - m_target->renderBox()->borderTop() - (borderWidth / 2) + buttonBottomShadowOffset, CSSPrimitiveValue::CSS_PX);
button->setInlineStyleProperty(CSSPropertyLeft, (-buttonWidth / 2) - m_target->renderBox()->borderLeft() - (borderWidth / 2), CSSPrimitiveValue::CSS_PX);
button->setInlineStyleProperty(CSSPropertyWidth, buttonWidth, CSSPrimitiveValue::CSS_PX);
......@@ -316,7 +316,7 @@ void DeleteButtonController::show(HTMLElement* element)
}
if (m_target->renderer()->style()->hasAutoZIndex()) {
m_target->setInlineStyleProperty(CSSPropertyZIndex, String::number(0));
m_target->setInlineStyleProperty(CSSPropertyZIndex, ASCIILiteral("0"));
m_wasAutoZIndex = true;
}
}
......
......@@ -53,7 +53,7 @@ String SVGNumberList::valueAsString() const
if (i > 0)
builder.append(' ');
builder.append(String::number(at(i)));
builder.appendNumber(at(i));
}
return builder.toString();
......
......@@ -38,7 +38,9 @@ String SVGPointList::valueAsString() const
builder.append(' '); // FIXME: Shouldn't we use commas to seperate?
const SVGPoint& point = at(i);
builder.append(String::number(point.x()) + ' ' + String::number(point.y()));
builder.appendNumber(point.x());
builder.append(' ');
builder.appendNumber(point.y());
}
return builder.toString();
......
......@@ -33,13 +33,13 @@ struct SVGPropertyTraits<FloatRect> {
static String toString(const FloatRect& type)
{
StringBuilder builder;
builder.append(String::number(type.x()));
builder.appendNumber(type.x());
builder.append(' ');
builder.append(String::number(type.y()));
builder.appendNumber(type.y());
builder.append(' ');
builder.append(String::number(type.width()));
builder.appendNumber(type.width());
builder.append(' ');
builder.append(String::number(type.height()));
builder.appendNumber(type.height());
return builder.toString();
}
};
......
2013-10-05 Darin Adler <darin@apple.com>
Cut down on use of String::number
https://bugs.webkit.org/show_bug.cgi?id=122382
Reviewed by Anders Carlsson.
* Shared/mac/RemoteLayerTreeTransaction.mm:
(WebKit::dumpChangedLayers): Use StringBuilder::appendNumber.
2013-10-05 Anders Carlsson <andersca@apple.com>
Fix cut and paste errors.
......
......@@ -219,9 +219,9 @@ static void dumpChangedLayers(StringBuilder& builder, const HashMap<uint64_t, Re
builder.append('\n');
writeIndent(builder, 3);
builder.append("(position ");
builder.append(String::number(layerProperties.position.x()));
builder.append(" ");
builder.append(String::number(layerProperties.position.y()));
builder.appendNumber(layerProperties.position.x());
builder.append(' ');
builder.appendNumber(layerProperties.position.y());
builder.append(')');
}
......@@ -229,9 +229,9 @@ static void dumpChangedLayers(StringBuilder& builder, const HashMap<uint64_t, Re
builder.append('\n');
writeIndent(builder, 3);
builder.append("(size ");
builder.append(String::number(layerProperties.size.width()));
builder.append(" ");
builder.append(String::number(layerProperties.size.height()));
builder.appendNumber(layerProperties.size.width());
builder.append(' ');
builder.appendNumber(layerProperties.size.height());
builder.append(')');
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment