Changeset 242014 in webkit
- Timestamp:
- Feb 24, 2019 3:57:25 PM (5 years ago)
- Location:
- trunk/Source
- Files:
-
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r242011 r242014 1 2019-02-20 Darin Adler <darin@apple.com> 2 3 Finish removing String::format 4 https://bugs.webkit.org/show_bug.cgi?id=194893 5 6 Reviewed by Daniel Bates. 7 8 * bytecode/CodeBlock.cpp: 9 (JSC::CodeBlock::nameForRegister): Use makeString instead of String::format, 10 using the new "pad" function. 11 1 12 2019-02-23 Robin Morisset <rmorisset@apple.com> 2 13 -
trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp
r241613 r242014 93 93 #include <wtf/SimpleStats.h> 94 94 #include <wtf/StringPrintStream.h> 95 #include <wtf/text/StringConcatenateNumbers.h> 95 96 #include <wtf/text/UniquedStringImpl.h> 96 97 … … 2889 2890 return "this"_s; 2890 2891 if (virtualRegister.isArgument()) 2891 return String::format("arguments[%3d]", virtualRegister.toArgument());2892 2893 return "";2892 return makeString("arguments[", pad(' ', 3, virtualRegister.toArgument()), ']'); 2893 2894 return emptyString(); 2894 2895 } 2895 2896 -
trunk/Source/WTF/ChangeLog
r241998 r242014 1 2019-02-20 Darin Adler <darin@apple.com> 2 3 Finish removing String::format 4 https://bugs.webkit.org/show_bug.cgi?id=194893 5 6 Reviewed by Daniel Bates. 7 8 * wtf/Assertions.cpp: 9 (WTF::createWithFormatAndArguments): Moved this here from WTFString.cpp. 10 (WTFLog): Use WTF::createWithFormatAndArguments instead of String::format. 11 12 * wtf/HexNumber.h: Deleted unneeded toString function. 13 14 * wtf/text/StringConcatenate.h: Got rid of unneeded forward declaration of 15 StringTypeAdapter, since that's now in Forward.h. Tweaked formatting of templates 16 a bit. Use function templates for writeTo functions rather than having two of each. 17 Removed unused toString functions. Optimized case where we use have a UChar* and 18 a length of zero to not force the result to be 16-bit. Also gets rid of a small 19 NO_RETURN_DUE_TO_CRASH mess that we don't need. Refactored constructors to use some 20 static member helper functions to compute string lengths. Added the pad function 21 and the PaddingSpecification struct template, so we can add padding to anything 22 we can turn into a string. Got rid of the special case overload for single 23 arguments, since it only worked for things that the String constructor can handle. 24 Instead we will now use StringTypeAdapter, which works for more types. Possibly 25 less optimal for some special cases, which we could specialize for later if we like. 26 * wtf/text/StringConcatenateNumbers.h: Ditto. 27 * wtf/text/StringOperators.h: Ditto. 28 * wtf/text/StringView.h: Ditto. 29 30 * wtf/text/WTFString.cpp: 31 (WTF::createWithFormatAndArguments): Deleted. 32 (WTF::String::format): Deleted. 33 * wtf/text/WTFString.h: Deleted declaration of String::format. 34 1 35 2019-02-23 Michael Catanzaro <mcatanzaro@igalia.com> 2 36 -
trunk/Source/WTF/wtf/Assertions.cpp
r237099 r242014 75 75 #endif 76 76 77 namespace WTF { 78 79 WTF_ATTRIBUTE_PRINTF(1, 0) static String createWithFormatAndArguments(const char* format, va_list args) 80 { 81 va_list argsCopy; 82 va_copy(argsCopy, args); 83 84 ALLOW_NONLITERAL_FORMAT_BEGIN 85 86 #if USE(CF) && !OS(WINDOWS) 87 if (strstr(format, "%@")) { 88 auto cfFormat = adoptCF(CFStringCreateWithCString(kCFAllocatorDefault, format, kCFStringEncodingUTF8)); 89 auto result = adoptCF(CFStringCreateWithFormatAndArguments(kCFAllocatorDefault, nullptr, cfFormat.get(), args)); 90 va_end(argsCopy); 91 return result.get(); 92 } 93 #endif 94 95 // Do the format once to get the length. 96 #if COMPILER(MSVC) 97 int result = _vscprintf(format, args); 98 #else 99 char ch; 100 int result = vsnprintf(&ch, 1, format, args); 101 #endif 102 103 if (!result) { 104 va_end(argsCopy); 105 return emptyString(); 106 } 107 if (result < 0) { 108 va_end(argsCopy); 109 return { }; 110 } 111 112 Vector<char, 256> buffer; 113 unsigned length = result; 114 buffer.grow(length + 1); 115 116 // Now do the formatting again, guaranteed to fit. 117 vsnprintf(buffer.data(), buffer.size(), format, argsCopy); 118 va_end(argsCopy); 119 120 ALLOW_NONLITERAL_FORMAT_END 121 122 return StringImpl::create(reinterpret_cast<const LChar*>(buffer.data()), length); 123 } 124 125 } 126 77 127 extern "C" { 78 128 … … 400 450 401 451 ALLOW_NONLITERAL_FORMAT_BEGIN 402 String loggingString = String::format(format, args);452 String loggingString = WTF::createWithFormatAndArguments(format, args); 403 453 ALLOW_NONLITERAL_FORMAT_END 404 454 -
trunk/Source/WTF/wtf/HexNumber.h
r241751 r242014 103 103 bool is8Bit() const { return true; } 104 104 template<typename CharacterType> void writeTo(CharacterType* destination) const { StringImpl::copyCharacters(destination, characters(), length()); } 105 String toString() const { return { characters(), length() }; }106 105 107 106 private: -
trunk/Source/WTF/wtf/text/StringConcatenate.h
r237099 r242014 26 26 #pragma once 27 27 28 #include < string.h>28 #include <cstring> 29 29 #include <wtf/CheckedArithmetic.h> 30 30 #include <wtf/text/AtomicString.h> … … 39 39 namespace WTF { 40 40 41 template<typename StringType, typename> 42 class StringTypeAdapter; 43 44 template<> 45 class StringTypeAdapter<char, void> { 41 template<> class StringTypeAdapter<char, void> { 46 42 public: 47 43 StringTypeAdapter(char character) 48 : m_character (character)44 : m_character { character } 49 45 { 50 46 } … … 52 48 unsigned length() { return 1; } 53 49 bool is8Bit() { return true; } 50 template<typename CharacterType> void writeTo(CharacterType* destination) const { *destination = m_character; } 51 52 private: 53 char m_character; 54 }; 55 56 template<> class StringTypeAdapter<UChar, void> { 57 public: 58 StringTypeAdapter(UChar character) 59 : m_character { character } 60 { 61 } 62 63 unsigned length() const { return 1; } 64 bool is8Bit() const { return isLatin1(m_character); } 54 65 55 66 void writeTo(LChar* destination) const 56 67 { 68 ASSERT(is8Bit()); 57 69 *destination = m_character; 58 70 } 59 71 60 void writeTo(UChar* destination) const 61 { 62 *destination = m_character; 63 } 64 65 String toString() const { return String(&m_character, 1); } 66 67 private: 68 char m_character; 69 }; 70 71 template<> 72 class StringTypeAdapter<UChar, void> { 73 public: 74 StringTypeAdapter(UChar character) 75 : m_character(character) 76 { 77 } 78 79 unsigned length() const { return 1; } 80 bool is8Bit() const { return m_character <= 0xff; } 81 82 void writeTo(LChar* destination) const 83 { 84 ASSERT(is8Bit()); 85 *destination = static_cast<LChar>(m_character); 86 } 87 88 void writeTo(UChar* destination) const 89 { 90 *destination = m_character; 91 } 92 93 String toString() const { return String(&m_character, 1); } 72 void writeTo(UChar* destination) const { *destination = m_character; } 94 73 95 74 private: … … 97 76 }; 98 77 99 template<> 100 class StringTypeAdapter<const LChar*, void> { 78 template<> class StringTypeAdapter<const LChar*, void> { 101 79 public: 102 80 StringTypeAdapter(const LChar* characters) 103 : m_characters(characters) 104 { 105 size_t length = strlen(reinterpret_cast<const char*>(characters)); 106 RELEASE_ASSERT(length <= String::MaxLength); 107 m_length = static_cast<unsigned>(length); 81 : m_characters { characters } 82 , m_length { computeLength(characters) } 83 { 108 84 } 109 85 110 86 unsigned length() const { return m_length; } 111 87 bool is8Bit() const { return true; } 112 113 void writeTo(LChar* destination) const 114 { 115 StringView(m_characters, m_length).getCharactersWithUpconvert(destination); 116 } 117 118 void writeTo(UChar* destination) const 119 { 120 StringView(m_characters, m_length).getCharactersWithUpconvert(destination); 121 } 122 123 String toString() const { return String(m_characters, m_length); } 124 125 private: 88 template<typename CharacterType> void writeTo(CharacterType* destination) const { StringImpl::copyCharacters(destination, m_characters, m_length); } 89 90 private: 91 static unsigned computeLength(const LChar* characters) 92 { 93 size_t length = std::strlen(reinterpret_cast<const char*>(characters)); 94 RELEASE_ASSERT(length <= String::MaxLength); 95 return static_cast<unsigned>(length); 96 } 97 126 98 const LChar* m_characters; 127 99 unsigned m_length; 128 100 }; 129 101 130 template<> 131 class StringTypeAdapter<const UChar*, void> { 102 template<> class StringTypeAdapter<const UChar*, void> { 132 103 public: 133 104 StringTypeAdapter(const UChar* characters) 134 : m_characters(characters) 105 : m_characters { characters } 106 , m_length { computeLength(characters) } 107 { 108 } 109 110 unsigned length() const { return m_length; } 111 bool is8Bit() const { return !m_length; } 112 void writeTo(LChar*) const { ASSERT(!m_length); } 113 void writeTo(UChar* destination) const { StringImpl::copyCharacters(destination, m_characters, m_length); } 114 115 private: 116 static unsigned computeLength(const UChar* characters) 135 117 { 136 118 size_t length = 0; 137 while ( m_characters[length])119 while (characters[length]) 138 120 ++length; 139 121 RELEASE_ASSERT(length <= String::MaxLength); 140 m_length = static_cast<unsigned>(length); 141 } 142 143 unsigned length() const { return m_length; } 144 bool is8Bit() const { return false; } 145 146 NO_RETURN_DUE_TO_CRASH void writeTo(LChar*) const 147 { 148 CRASH(); // FIXME make this a compile-time failure https://bugs.webkit.org/show_bug.cgi?id=165791 149 } 150 151 void writeTo(UChar* destination) const 152 { 153 memcpy(destination, m_characters, m_length * sizeof(UChar)); 154 } 155 156 String toString() const { return String(m_characters, m_length); } 157 158 private: 122 return static_cast<unsigned>(length); 123 } 124 159 125 const UChar* m_characters; 160 126 unsigned m_length; 161 127 }; 162 128 163 template<> 164 class StringTypeAdapter<const char*, void> : public StringTypeAdapter<const LChar*, void> { 129 template<> class StringTypeAdapter<const char*, void> : public StringTypeAdapter<const LChar*, void> { 165 130 public: 166 131 StringTypeAdapter(const char* characters) 167 : StringTypeAdapter<const LChar*, void>(reinterpret_cast<const LChar*>(characters)) 168 { 169 } 170 }; 171 172 template<> 173 class StringTypeAdapter<char*, void> : public StringTypeAdapter<const char*, void> { 132 : StringTypeAdapter<const LChar*, void> { reinterpret_cast<const LChar*>(characters) } 133 { 134 } 135 }; 136 137 template<> class StringTypeAdapter<char*, void> : public StringTypeAdapter<const char*, void> { 174 138 public: 175 139 StringTypeAdapter(const char* characters) 176 : StringTypeAdapter<const char*, void>(characters) 177 { 178 } 179 }; 180 181 template<> 182 class StringTypeAdapter<ASCIILiteral, void> : public StringTypeAdapter<const char*, void> { 140 : StringTypeAdapter<const char*, void> { characters } 141 { 142 } 143 }; 144 145 template<> class StringTypeAdapter<ASCIILiteral, void> : public StringTypeAdapter<const char*, void> { 183 146 public: 184 147 StringTypeAdapter(ASCIILiteral characters) 185 : StringTypeAdapter<const char*, void>(characters) 186 { 187 } 188 }; 189 190 template<> 191 class StringTypeAdapter<Vector<char>, void> { 148 : StringTypeAdapter<const char*, void> { characters } 149 { 150 } 151 }; 152 153 template<> class StringTypeAdapter<Vector<char>, void> { 192 154 public: 193 155 StringTypeAdapter(const Vector<char>& vector) 194 : m_vector (vector)156 : m_vector { vector } 195 157 { 196 158 } … … 198 160 size_t length() const { return m_vector.size(); } 199 161 bool is8Bit() const { return true; } 200 201 void writeTo(LChar* destination) const 202 { 203 StringView(reinterpret_cast<const LChar*>(m_vector.data()), m_vector.size()).getCharactersWithUpconvert(destination); 204 } 205 206 void writeTo(UChar* destination) const 207 { 208 StringView(reinterpret_cast<const LChar*>(m_vector.data()), m_vector.size()).getCharactersWithUpconvert(destination); 209 } 210 211 String toString() const { return String(m_vector.data(), m_vector.size()); } 212 213 private: 162 template<typename CharacterType> void writeTo(CharacterType* destination) const { StringImpl::copyCharacters(destination, characters(), length()); } 163 164 private: 165 const LChar* characters() const 166 { 167 return reinterpret_cast<const LChar*>(m_vector.data()); 168 } 169 214 170 const Vector<char>& m_vector; 215 171 }; 216 172 217 template<> 218 class StringTypeAdapter<String, void> { 173 template<> class StringTypeAdapter<String, void> { 219 174 public: 220 175 StringTypeAdapter(const String& string) 221 : m_string (string)176 : m_string { string } 222 177 { 223 178 } … … 225 180 unsigned length() const { return m_string.length(); } 226 181 bool is8Bit() const { return m_string.isNull() || m_string.is8Bit(); } 227 228 void writeTo(LChar* destination) const 229 { 230 StringView(m_string).getCharactersWithUpconvert(destination); 182 template<typename CharacterType> void writeTo(CharacterType* destination) const 183 { 184 StringView { m_string }.getCharactersWithUpconvert(destination); 231 185 WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING(); 232 186 } 233 187 234 void writeTo(UChar* destination) const235 {236 StringView(m_string).getCharactersWithUpconvert(destination);237 WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING();238 }239 240 String toString() const { return m_string; }241 242 188 private: 243 189 const String& m_string; 244 190 }; 245 191 246 template<> 247 class StringTypeAdapter<AtomicString, void> : public StringTypeAdapter<String, void> { 192 template<> class StringTypeAdapter<AtomicString, void> : public StringTypeAdapter<String, void> { 248 193 public: 249 194 StringTypeAdapter(const AtomicString& string) 250 : StringTypeAdapter<String, void>(string.string()) 251 { 252 } 195 : StringTypeAdapter<String, void> { string.string() } 196 { 197 } 198 }; 199 200 template<typename UnderlyingAdapterType> struct PaddingSpecification { 201 LChar character; 202 unsigned length; 203 UnderlyingAdapterType underlyingAdapter; 204 }; 205 206 template<typename StringType> PaddingSpecification<StringTypeAdapter<StringType>> pad(char character, unsigned length, StringType adapter) 207 { 208 return { static_cast<LChar>(character), length, StringTypeAdapter<StringType> { adapter } }; 209 } 210 211 template<typename UnderlyingAdapterType> class StringTypeAdapter<PaddingSpecification<UnderlyingAdapterType>> { 212 public: 213 StringTypeAdapter(const PaddingSpecification<UnderlyingAdapterType>& padding) 214 : m_padding { padding } 215 { 216 } 217 218 unsigned length() const { return std::max(m_padding.length, m_padding.underlyingAdapter.length()); } 219 bool is8Bit() const { return m_padding.underlyingAdapter.is8Bit(); } 220 template<typename CharacterType> void writeTo(CharacterType* destination) const 221 { 222 unsigned underlyingLength = m_padding.underlyingAdapter.length(); 223 unsigned count = 0; 224 if (underlyingLength < m_padding.length) { 225 count = m_padding.length - underlyingLength; 226 for (unsigned i = 0; i < count; ++i) 227 destination[i] = m_padding.character; 228 } 229 m_padding.underlyingAdapter.writeTo(destination + count); 230 } 231 232 private: 233 const PaddingSpecification<UnderlyingAdapterType>& m_padding; 253 234 }; 254 235 … … 315 296 } 316 297 317 // Convenience only.318 template<typename StringType>319 String makeString(StringType string)320 {321 return String(string);322 }323 324 298 template<typename... StringTypes> 325 299 String makeString(StringTypes... strings) … … 334 308 335 309 using WTF::makeString; 310 using WTF::pad; 336 311 using WTF::tryMakeString; 337 312 -
trunk/Source/WTF/wtf/text/StringConcatenateNumbers.h
r241751 r242014 43 43 bool is8Bit() const { return true; } 44 44 template<typename CharacterType> void writeTo(CharacterType* destination) const { writeNumberToBufferSigned(m_number, destination); } 45 String toString() const { return String::number(m_number); }46 45 47 46 private: … … 60 59 bool is8Bit() const { return true; } 61 60 template<typename CharacterType> void writeTo(CharacterType* destination) const { writeNumberToBufferUnsigned(m_number, destination); } 62 String toString() const { return String::number(m_number); }63 61 64 62 private: … … 72 70 { 73 71 numberToString(number, m_buffer); 74 m_length = st rlen(m_buffer);72 m_length = std::strlen(m_buffer); 75 73 } 76 74 … … 78 76 bool is8Bit() const { return true; } 79 77 template<typename CharacterType> void writeTo(CharacterType* destination) const { StringImpl::copyCharacters(destination, buffer(), m_length); } 80 String toString() const { return { buffer(), m_length }; }81 78 82 79 private: … … 93 90 FormattedNumber numberFormatter; 94 91 numberToFixedPrecisionString(number, significantFigures, numberFormatter.m_buffer, trailingZerosTruncatingPolicy == TruncateTrailingZeros); 95 numberFormatter.m_length = st rlen(numberFormatter.m_buffer);92 numberFormatter.m_length = std::strlen(numberFormatter.m_buffer); 96 93 return numberFormatter; 97 94 } … … 101 98 FormattedNumber numberFormatter; 102 99 numberToFixedWidthString(number, decimalPlaces, numberFormatter.m_buffer); 103 numberFormatter.m_length = st rlen(numberFormatter.m_buffer);100 numberFormatter.m_length = std::strlen(numberFormatter.m_buffer); 104 101 return numberFormatter; 105 102 } … … 113 110 }; 114 111 115 template<> 116 class StringTypeAdapter<FormattedNumber> { 112 template<> class StringTypeAdapter<FormattedNumber> { 117 113 public: 118 114 StringTypeAdapter(const FormattedNumber& number) … … 124 120 bool is8Bit() const { return true; } 125 121 template<typename CharacterType> void writeTo(CharacterType* destination) const { StringImpl::copyCharacters(destination, m_number.buffer(), m_number.length()); } 126 String toString() const { return { m_number.buffer(), m_number.length() }; }127 122 128 123 private: -
trunk/Source/WTF/wtf/text/StringOperators.h
r239282 r242014 24 24 namespace WTF { 25 25 26 template<typename StringType1, typename StringType2> 27 class StringAppend { 26 template<typename StringType1, typename StringType2> class StringAppend { 28 27 public: 29 28 StringAppend(StringType1 string1, StringType2 string2) 30 : m_string1 (string1)31 , m_string2 (string2)29 : m_string1 { string1 } 30 , m_string2 { string2 } 32 31 { 33 32 } … … 86 85 public: 87 86 StringTypeAdapter<StringAppend<StringType1, StringType2>>(StringAppend<StringType1, StringType2>& buffer) 88 : m_buffer (buffer)87 : m_buffer { buffer } 89 88 { 90 89 } 91 90 92 unsigned length() { return m_buffer.length(); } 93 94 bool is8Bit() { return m_buffer.is8Bit(); } 95 96 void writeTo(LChar* destination) { m_buffer.writeTo(destination); } 97 void writeTo(UChar* destination) { m_buffer.writeTo(destination); } 98 99 String toString() const { return m_buffer; } 91 unsigned length() const { return m_buffer.length(); } 92 bool is8Bit() const { return m_buffer.is8Bit(); } 93 template<typename CharacterType> void writeTo(CharacterType* destination) const { m_buffer.writeTo(destination); } 100 94 101 95 private: -
trunk/Source/WTF/wtf/text/StringView.h
r239427 r242014 566 566 567 567 #if !CHECK_STRINGVIEW_LIFETIME 568 568 569 inline void StringView::invalidate(const StringImpl&) 569 570 { 570 571 } 572 571 573 #endif 572 574 573 template<typename StringType, typename> class StringTypeAdapter;574 575 575 template<> class StringTypeAdapter<StringView, void> { 576 576 public: 577 577 StringTypeAdapter(StringView string) 578 : m_string (string)578 : m_string { string } 579 579 { 580 580 } … … 582 582 unsigned length() { return m_string.length(); } 583 583 bool is8Bit() { return m_string.is8Bit(); } 584 void writeTo(LChar* destination) { m_string.getCharactersWithUpconvert(destination); } 585 void writeTo(UChar* destination) { m_string.getCharactersWithUpconvert(destination); } 586 587 String toString() const { return m_string.toString(); } 584 template<typename CharacterType> void writeTo(CharacterType* destination) { m_string.getCharactersWithUpconvert(destination); } 588 585 589 586 private: -
trunk/Source/WTF/wtf/text/WTFString.cpp
r241233 r242014 450 450 } 451 451 452 WTF_ATTRIBUTE_PRINTF(1, 0) static String createWithFormatAndArguments(const char *format, va_list args)453 {454 va_list argsCopy;455 va_copy(argsCopy, args);456 457 ALLOW_NONLITERAL_FORMAT_BEGIN458 459 #if USE(CF) && !OS(WINDOWS)460 if (strstr(format, "%@")) {461 auto cfFormat = adoptCF(CFStringCreateWithCString(kCFAllocatorDefault, format, kCFStringEncodingUTF8));462 auto result = adoptCF(CFStringCreateWithFormatAndArguments(kCFAllocatorDefault, nullptr, cfFormat.get(), args));463 va_end(argsCopy);464 return result.get();465 }466 #endif467 468 // Do the format once to get the length.469 #if COMPILER(MSVC)470 int result = _vscprintf(format, args);471 #else472 char ch;473 int result = vsnprintf(&ch, 1, format, args);474 #endif475 476 if (!result) {477 va_end(argsCopy);478 return emptyString();479 }480 if (result < 0) {481 va_end(argsCopy);482 return String();483 }484 485 Vector<char, 256> buffer;486 unsigned len = result;487 buffer.grow(len + 1);488 489 // Now do the formatting again, guaranteed to fit.490 vsnprintf(buffer.data(), buffer.size(), format, argsCopy);491 va_end(argsCopy);492 493 ALLOW_NONLITERAL_FORMAT_END494 495 return StringImpl::create(reinterpret_cast<const LChar*>(buffer.data()), len);496 }497 498 String String::format(const char *format, ...)499 {500 va_list args;501 va_start(args, format);502 String result = createWithFormatAndArguments(format, args);503 va_end(args);504 return result;505 }506 507 452 String String::number(int number) 508 453 { -
trunk/Source/WTF/wtf/text/WTFString.h
r239439 r242014 261 261 // Use convertToASCIILowercase instead if ASCII case insensitive comparison is desired. 262 262 WTF_EXPORT_PRIVATE String foldCase() const; 263 264 WTF_EXPORT_PRIVATE static String format(const char *, ...) WTF_ATTRIBUTE_PRINTF(1, 2);265 263 266 264 // Returns an uninitialized string. The characters needs to be written -
trunk/Source/WebCore/ChangeLog
r242013 r242014 1 2019-02-20 Darin Adler <darin@apple.com> 2 3 Finish removing String::format 4 https://bugs.webkit.org/show_bug.cgi?id=194893 5 6 Reviewed by Daniel Bates. 7 8 * dom/Document.cpp: 9 (WebCore::Document::lastModified const): Use makeString and pad. 10 * html/FTPDirectoryDocument.cpp: 11 (WebCore::processFileDateString): Ditto. 12 13 * mathml/MathMLElement.cpp: 14 (WebCore::convertToPercentageIfNeeded): Use makeString and FormattedNumber. 15 16 * page/cocoa/ResourceUsageOverlayCocoa.mm: 17 (WebCore::ResourceUsageOverlay::platformDraw): Use makeString and pad. 18 19 * page/linux/ResourceUsageOverlayLinux.cpp: 20 (WebCore::cpuUsageString): Use makeString, FormattedNumber, and pad. 21 (WebCore::gcTimerString): Use String::number. 22 23 * platform/DateComponents.cpp: 24 (WebCore::DateComponents::toStringForTime const): Use makeString and pad. 25 (WebCore::DateComponents::toString const): Ditto. 26 27 * platform/LocalizedStrings.cpp: Removed comment that mentioned String::format, 28 and that was also inaccurate. 29 30 * platform/audio/HRTFElevation.cpp: 31 (WebCore::HRTFElevation::calculateKernelsForAzimuthElevation): 32 Use makeString and pad. 33 * platform/mock/MockRealtimeVideoSource.cpp: 34 (WebCore::MockRealtimeVideoSource::drawText): Ditto. 35 * rendering/RenderLayerCompositor.cpp: 36 (WebCore::RenderLayerCompositor::logLayerInfo): Ditto. 37 * rendering/RenderTheme.cpp: 38 (WebCore::RenderTheme::formatMediaControlsTime const): Ditto. 39 1 40 2019-02-24 Michael Catanzaro <mcatanzaro@igalia.com> 2 41 -
trunk/Source/WebCore/dom/Document.cpp
r241932 r242014 5010 5010 dateTime = loader()->response().lastModified(); 5011 5011 5012 // FIXME: If this document came from the file system, the HTML5 5013 // specification tells us to read the last modification date from the file 5014 // system. 5012 // FIXME: If this document came from the file system, the HTML specification tells 5013 // us to read the last modification date from the file system. 5015 5014 if (!dateTime) 5016 5015 dateTime = WallTime::now(); … … 5018 5017 auto ctime = dateTime.value().secondsSinceEpoch().secondsAs<time_t>(); 5019 5018 auto localDateTime = std::localtime(&ctime); 5020 return String::format("%02d/%02d/%04d %02d:%02d:%02d", localDateTime->tm_mon + 1, localDateTime->tm_mday, 1900 + localDateTime->tm_year, localDateTime->tm_hour, localDateTime->tm_min, localDateTime->tm_sec); 5019 return makeString(pad('0', 2, localDateTime->tm_mon + 1), '/', 5020 pad('0', 2, localDateTime->tm_mday), '/', 5021 pad('0', 4, 1900 + localDateTime->tm_year), ' ', 5022 pad('0', 2, localDateTime->tm_hour), ':', 5023 pad('0', 2, localDateTime->tm_min), ':', 5024 pad('0', 2, localDateTime->tm_sec)); 5021 5025 } 5022 5026 -
trunk/Source/WebCore/html/FTPDirectoryDocument.cpp
r241244 r242014 211 211 if (hour == 0) 212 212 hour = 12; 213 timeOfDay = String::format(", %i:%02i AM", hour, fileTime.tm_min);213 timeOfDay = makeString(", ", hour, ':', pad('0', 2, fileTime.tm_min), " AM"); 214 214 } else { 215 215 hour = hour - 12; 216 216 if (hour == 0) 217 217 hour = 12; 218 timeOfDay = String::format(", %i:%02i PM", hour, fileTime.tm_min);218 timeOfDay = makeString(", ", hour, ':', pad('0', 2, fileTime.tm_min), " PM"); 219 219 } 220 220 } -
trunk/Source/WebCore/mathml/MathMLElement.cpp
r241947 r242014 40 40 #include "RenderTableCell.h" 41 41 #include <wtf/IsoMallocInlines.h> 42 #include <wtf/text/StringConcatenateNumbers.h> 42 43 43 44 namespace WebCore { … … 100 101 static String convertToPercentageIfNeeded(const AtomicString& value) 101 102 { 103 // FIXME: Might be better to use double than float. 104 // FIXME: Might be better to use "shortest" numeric formatting instead of fixed width. 102 105 bool ok = false; 103 106 float unitlessValue = value.toFloat(&ok); 104 if ( ok)105 return String::format("%.3f%%", unitlessValue * 100.0);106 return value;107 if (!ok) 108 return value; 109 return makeString(FormattedNumber::fixedWidth(unitlessValue * 100, 3), '%'); 107 110 } 108 111 … … 117 120 } else if (name == mathcolorAttr) 118 121 addPropertyToPresentationAttributeStyle(style, CSSPropertyColor, value); 119 // FIXME: deprecated attributes that should loose in a conflict with a non deprecated attribute122 // FIXME: The following are deprecated attributes that should lose if there is a conflict with a non-deprecated attribute. 120 123 else if (name == fontsizeAttr) 121 124 addPropertyToPresentationAttributeStyle(style, CSSPropertyFontSize, value); … … 135 138 } else { 136 139 ASSERT(!isPresentationAttribute(name)); 137 StyledElement::collectStyleForPresentationAttribute(name, value 138 , style); 140 StyledElement::collectStyleForPresentationAttribute(name, value, style); 139 141 } 140 142 } -
trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm
r241244 r242014 469 469 size_t external = category.externalSize.last(); 470 470 471 String label = String::format("% 11s: %s", category.name.ascii().data(), formatByteNumber(dirty).ascii().data());471 String label = makeString(pad(' ', 11, category.name), ": ", formatByteNumber(dirty)); 472 472 if (external) 473 473 label = label + makeString(" + ", formatByteNumber(external)); -
trunk/Source/WebCore/page/linux/ResourceUsageOverlayLinux.cpp
r241751 r242014 47 47 if (cpuUsage < 0) 48 48 return "<unknown>"_s; 49 return String::format("%.1f%%", cpuUsage);49 return makeString(FormattedNumber::fixedWidth(cpuUsage, 1), '%'); 50 50 } 51 51 … … 65 65 if (std::isnan(timerFireDate)) 66 66 return "[not scheduled]"_s; 67 return String:: format("%g",(timerFireDate - now).seconds());67 return String::number((timerFireDate - now).seconds()); 68 68 } 69 69 -
trunk/Source/WebCore/platform/DateComponents.cpp
r237990 r242014 36 36 #include <wtf/DateMath.h> 37 37 #include <wtf/MathExtras.h> 38 #include <wtf/text/ WTFString.h>38 #include <wtf/text/StringConcatenateNumbers.h> 39 39 40 40 namespace WebCore { … … 694 694 #endif 695 695 case None: 696 return String::format("%02d:%02d", m_hour, m_minute);696 return makeString(pad('0', 2, m_hour), ':', pad('0', 2, m_minute)); 697 697 case Second: 698 return String::format("%02d:%02d:%02d", m_hour, m_minute, m_second);698 return makeString(pad('0', 2, m_hour), ':', pad('0', 2, m_minute), ':', pad('0', 2, m_second)); 699 699 case Millisecond: 700 return String::format("%02d:%02d:%02d.%03d", m_hour, m_minute, m_second, m_millisecond);700 return makeString(pad('0', 2, m_hour), ':', pad('0', 2, m_minute), ':', pad('0', 2, m_second), '.', pad('0', 3, m_millisecond)); 701 701 } 702 702 } … … 706 706 switch (m_type) { 707 707 case Date: 708 return String::format("%04d-%02d-%02d", m_year, m_month + 1, m_monthDay);708 return makeString(pad('0', 4, m_year), '-', pad('0', 2, m_month + 1), '-', pad('0', 2, m_monthDay)); 709 709 case DateTime: 710 return String::format("%04d-%02d-%02dT", m_year, m_month + 1, m_monthDay) 711 + toStringForTime(format) + "Z"_str; 710 return makeString(pad('0', 4, m_year), '-', pad('0', 2, m_month + 1), '-', pad('0', 2, m_monthDay), 'T', toStringForTime(format), 'Z'); 712 711 case DateTimeLocal: 713 return String::format("%04d-%02d-%02dT", m_year, m_month + 1, m_monthDay) 714 + toStringForTime(format); 712 return makeString(pad('0', 4, m_year), '-', pad('0', 2, m_month + 1), '-', pad('0', 2, m_monthDay), 'T', toStringForTime(format)); 715 713 case Month: 716 return String::format("%04d-%02d", m_year, m_month + 1);714 return makeString(pad('0', 4, m_year), '-', pad('0', 2, m_month + 1)); 717 715 case Time: 718 716 return toStringForTime(format); 719 717 case Week: 720 return String::format("%04d-W%02d", m_year, m_week);718 return makeString(pad('0', 4, m_year), "-W", pad('0', 2, m_week)); 721 719 case Invalid: 722 720 break; -
trunk/Source/WebCore/platform/LocalizedStrings.cpp
r240710 r242014 44 44 namespace WebCore { 45 45 46 // We can't use String::format for two reasons: 47 // 1) It doesn't handle non-ASCII characters in the format string. 48 // 2) It doesn't handle the %2$d syntax. 49 // Note that because |format| is used as the second parameter to va_start, it cannot be a reference 46 // Because |format| is used as the second parameter to va_start, it cannot be a reference 50 47 // type according to section 18.7/3 of the C++ N1905 standard. 51 48 String formatLocalizedString(String format, ...) … … 74 71 75 72 #if !USE(CF) 73 76 74 String localizedString(const char* key) 77 75 { 78 76 return String::fromUTF8(key, strlen(key)); 79 77 } 78 80 79 #endif 81 80 -
trunk/Source/WebCore/platform/audio/HRTFElevation.cpp
r239535 r242014 177 177 AudioChannel* rightEarImpulseResponse = response->channel(AudioBus::ChannelRight); 178 178 #else 179 String resourceName = String::format("IRC_%s_C_R0195_T%03d_P%03d", subjectName.utf8().data(), azimuth, positiveElevation);179 String resourceName = makeString("IRC_", subjectName, "_C_R0195_T", pad('0', 3, azimuth), "_P", pad('0', 3, positiveElevation)); 180 180 181 181 RefPtr<AudioBus> impulseResponse(AudioBus::loadPlatformResource(resourceName.utf8().data(), sampleRate)); -
trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp
r240892 r242014 351 351 context.setFillColor(Color::white); 352 352 context.setTextDrawingMode(TextModeFill); 353 String string = String::format("%02u:%02u:%02u.%03u", hours, minutes, seconds, milliseconds % 1000);353 String string = makeString(pad('0', 2, hours), ':', pad('0', 2, minutes), ':', pad('0', 2, seconds), '.', pad('0', 3, milliseconds % 1000)); 354 354 context.drawText(timeFont, TextRun((StringView(string))), timeLocation); 355 355 356 string = String::format("%06u", m_frameNumber++);356 string = makeString(pad('0', 6, m_frameNumber++)); 357 357 timeLocation.move(0, m_baseFontSize); 358 358 context.drawText(timeFont, TextRun((StringView(string))), timeLocation); -
trunk/Source/WebCore/rendering/RenderLayerCompositor.cpp
r241860 r242014 61 61 #include "TiledBacking.h" 62 62 #include "TransformState.h" 63 #include <wtf/HexNumber.h> 63 64 #include <wtf/MemoryPressureHandler.h> 64 65 #include <wtf/SetForScope.h> … … 1324 1325 1325 1326 StringBuilder logString; 1326 logString.append(String::format("%*p id %" PRIu64 " (%.3f,%.3f-%.3f,%.3f) %.2fKB", 12 + depth * 2, &layer, backing->graphicsLayer()->primaryLayerID(), 1327 absoluteBounds.x().toFloat(), absoluteBounds.y().toFloat(), absoluteBounds.maxX().toFloat(), absoluteBounds.maxY().toFloat(), 1328 backing->backingStoreMemoryEstimate() / 1024)); 1329 1327 logString.append(makeString(pad(' ', 12 + depth * 2, hex(reinterpret_cast<uintptr_t>(&layer))), " id ", backing->graphicsLayer()->primaryLayerID(), " (", FormattedNumber::fixedWidth(absoluteBounds.x().toFloat(), 3), ',', FormattedNumber::fixedWidth(absoluteBounds.y().toFloat(), 3), '-', FormattedNumber::fixedWidth(absoluteBounds.maxX().toFloat(), 3), ',', FormattedNumber::fixedWidth(absoluteBounds.maxY().toFloat(), 3), ") ", FormattedNumber::fixedWidth(backing->backingStoreMemoryEstimate() / 1024, 2), "KB")); 1328 1330 1329 if (!layer.renderer().style().hasAutoZIndex()) 1331 1330 logString.append(makeString(" z-index: ", layer.renderer().style().zIndex())); -
trunk/Source/WebCore/rendering/RenderTheme.cpp
r240628 r242014 47 47 #include <wtf/FileSystem.h> 48 48 #include <wtf/NeverDestroyed.h> 49 #include <wtf/text/StringConcatenateNumbers.h> 49 50 50 51 #if ENABLE(METER_ELEMENT) … … 569 570 if (!std::isfinite(time)) 570 571 time = 0; 571 int seconds = (int)fabsf(time); 572 // FIXME: Seems like it would be better to use std::lround here. 573 int seconds = static_cast<int>(std::abs(time)); 572 574 int hours = seconds / (60 * 60); 573 575 int minutes = (seconds / 60) % 60; 574 576 seconds %= 60; 575 if (hours) { 576 if (hours > 9) 577 return String::format("%s%02d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds); 578 579 return String::format("%s%01d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds); 580 } 581 582 return String::format("%s%02d:%02d", (time < 0 ? "-" : ""), minutes, seconds); 577 if (hours) 578 return makeString((time < 0 ? "-" : ""), hours, ':', pad('0', 2, minutes), ':', pad('0', 2, seconds)); 579 return makeString((time < 0 ? "-" : ""), pad('0', 2, minutes), ':', pad('0', 2, seconds)); 583 580 } 584 581 -
trunk/Source/WebKit/ChangeLog
r242012 r242014 1 2019-02-20 Darin Adler <darin@apple.com> 2 3 Finish removing String::format 4 https://bugs.webkit.org/show_bug.cgi?id=194893 5 6 Reviewed by Daniel Bates. 7 8 * UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm: 9 (WebKit::LocalAuthenticator::getAssertion): Use makeString, attempting to fix 10 a problem where we passed an NSData * to format with a "%s"." 11 1 12 2019-02-24 Michael Catanzaro <mcatanzaro@igalia.com> 2 13 -
trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm
r240892 r242014 401 401 weakThis->continueGetAssertionAfterUserConsented(consent, context, credentialId, userhandle); 402 402 }; 403 NSData *idData = selectedCredentialAttributes[(id)kSecAttrApplicationTag]; 404 StringView idStringView { static_cast<const LChar*>([idData bytes]), static_cast<unsigned>([idData length]) }; 403 405 m_connection->getUserConsent( 404 String::format("Log into %s with %s.", requestData().requestOptions.rpId.utf8().data(), selectedCredentialAttributes[(id)kSecAttrApplicationTag]),406 makeString("Log into ", requestData().requestOptions.rpId, " with ", idStringView, '.'), 405 407 (__bridge SecAccessControlRef)selectedCredentialAttributes[(id)kSecAttrAccessControl], 406 408 WTFMove(callback)); -
trunk/Source/WebKitLegacy/win/ChangeLog
r241949 r242014 1 2019-02-20 Darin Adler <darin@apple.com> 2 3 Finish removing String::format 4 https://bugs.webkit.org/show_bug.cgi?id=194893 5 6 Reviewed by Daniel Bates. 7 8 * FullscreenVideoController.cpp: 9 (timeToString): Use makeString and pad. 10 1 11 2019-02-22 Wenson Hsieh <wenson_hsieh@apple.com> 2 12 -
trunk/Source/WebKitLegacy/win/FullscreenVideoController.cpp
r239549 r242014 42 42 #include <windowsx.h> 43 43 #include <wtf/StdLibExtras.h> 44 #include <wtf/text/StringConcatenateNumbers.h> 44 45 45 46 #if USE(CA) … … 471 472 int minutes = (seconds / 60) % 60; 472 473 seconds %= 60; 473 474 if (hours) { 475 if (hours > 9) 476 return String::format("%s%02d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds); 477 return String::format("%s%01d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds); 478 } 479 480 return String::format("%s%02d:%02d", (time < 0 ? "-" : ""), minutes, seconds); 474 if (hours) 475 return makeString((time < 0 ? "-" : ""), hours, ':', pad('0', 2, minutes), ':', pad('0', 2, seconds)); 476 return makeString((time < 0 ? "-" : ""), pad('0', 2, minutes), ':', pad('0', 2, seconds)); 481 477 } 482 478
Note: See TracChangeset
for help on using the changeset viewer.