Changeset 128564 in webkit
- Timestamp:
- Sep 14, 2012 12:09:03 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r128559 r128564 1 2012-09-13 Patrick Gansterer <paroga@webkit.org> 2 3 Reuse floating point formatting of TextStream in [SVG]RenderTreeAsText.cpp 4 https://bugs.webkit.org/show_bug.cgi?id=96264 5 6 Reviewed by Benjamin Poulain. 7 8 RenderTreeAsText uses the same format for streaming out floats as TextStream 9 does. Replace formatNumberRespectingIntegers() with a new overload to the 10 operator<< to reuse the special cases for numbers which take advantage of 11 StringBuilder::appendNumber() and avoid a temporary StringImpl. 12 13 * platform/text/TextStream.cpp: 14 (WebCore::hasFractions): 15 (WebCore::TextStream::operator<<): 16 * platform/text/TextStream.h: 17 * rendering/RenderTreeAsText.cpp: 18 (WebCore::operator<<): 19 * rendering/RenderTreeAsText.h: 20 * rendering/svg/SVGRenderTreeAsText.cpp: 21 (WebCore::operator<<): 22 1 23 2012-09-13 Sheriff Bot <webkit.review.bot@gmail.com> 2 24 -
trunk/Source/WebCore/platform/text/TextStream.cpp
r128014 r128564 27 27 #include "TextStream.h" 28 28 29 #include <wtf/MathExtras.h> 29 30 #include <wtf/StringExtras.h> 30 31 #include <wtf/text/WTFString.h> … … 35 36 36 37 static const size_t printBufferSize = 100; // large enough for any integer or floating point value in string format, including trailing null character 38 39 static inline bool hasFractions(double val) 40 { 41 static const double s_epsilon = 0.0001; 42 int ival = static_cast<int>(val); 43 double dval = static_cast<double>(ival); 44 return fabs(val - dval) > s_epsilon; 45 } 37 46 38 47 TextStream& TextStream::operator<<(bool b) … … 108 117 } 109 118 119 TextStream& TextStream::operator<<(const FormatNumberRespectingIntegers& numberToFormat) 120 { 121 if (hasFractions(numberToFormat.value)) 122 return *this << numberToFormat.value; 123 124 m_text.appendNumber(static_cast<int>(numberToFormat.value)); 125 return *this; 126 } 127 110 128 String TextStream::release() 111 129 { -
trunk/Source/WebCore/platform/text/TextStream.h
r128014 r128564 35 35 class TextStream { 36 36 public: 37 struct FormatNumberRespectingIntegers { 38 FormatNumberRespectingIntegers(double number) : value(number) { } 39 double value; 40 }; 41 37 42 TextStream& operator<<(bool); 38 43 TextStream& operator<<(int); … … 47 52 TextStream& operator<<(const void*); 48 53 TextStream& operator<<(const String&); 54 TextStream& operator<<(const FormatNumberRespectingIntegers&); 49 55 50 56 String release(); -
trunk/Source/WebCore/rendering/RenderTreeAsText.cpp
r128014 r128564 80 80 static void writeLayers(TextStream&, const RenderLayer* rootLayer, RenderLayer*, const LayoutRect& paintDirtyRect, int indent = 0, RenderAsTextBehavior = RenderAsTextBehaviorNormal); 81 81 82 static inline bool hasFractions(double val)83 {84 static const double s_epsilon = 0.0001;85 int ival = static_cast<int>(val);86 double dval = static_cast<double>(ival);87 return fabs(val - dval) > s_epsilon;88 }89 90 String formatNumberRespectingIntegers(double value)91 {92 if (!hasFractions(value))93 return String::number(static_cast<int>(value));94 return String::number(value, ShouldRoundDecimalPlaces, 2);95 }96 97 82 TextStream& operator<<(TextStream& ts, const IntRect& r) 98 83 { … … 113 98 TextStream& operator<<(TextStream& ts, const FloatPoint& p) 114 99 { 115 ts << "(" << formatNumberRespectingIntegers(p.x());116 ts << "," << formatNumberRespectingIntegers(p.y());100 ts << "(" << TextStream::FormatNumberRespectingIntegers(p.x()); 101 ts << "," << TextStream::FormatNumberRespectingIntegers(p.y()); 117 102 ts << ")"; 118 103 return ts; … … 121 106 TextStream& operator<<(TextStream& ts, const FloatSize& s) 122 107 { 123 ts << "width=" << formatNumberRespectingIntegers(s.width());124 ts << " height=" << formatNumberRespectingIntegers(s.height());108 ts << "width=" << TextStream::FormatNumberRespectingIntegers(s.width()); 109 ts << " height=" << TextStream::FormatNumberRespectingIntegers(s.height()); 125 110 return ts; 126 111 } -
trunk/Source/WebCore/rendering/RenderTreeAsText.h
r116009 r128564 29 29 30 30 #include <wtf/Forward.h> 31 #include <wtf/MathExtras.h>32 31 33 32 namespace WebCore { … … 99 98 String markerTextForListItem(Element*); 100 99 101 String formatNumberRespectingIntegers(double);102 103 100 } // namespace WebCore 104 101 -
trunk/Source/WebCore/rendering/svg/SVGRenderTreeAsText.cpp
r123025 r128564 135 135 TextStream& operator<<(TextStream& ts, const FloatRect& r) 136 136 { 137 ts << "at (" << formatNumberRespectingIntegers(r.x());138 ts << "," << formatNumberRespectingIntegers(r.y());139 ts << ") size " << formatNumberRespectingIntegers(r.width());140 ts << "x" << formatNumberRespectingIntegers(r.height());137 ts << "at (" << TextStream::FormatNumberRespectingIntegers(r.x()); 138 ts << "," << TextStream::FormatNumberRespectingIntegers(r.y()); 139 ts << ") size " << TextStream::FormatNumberRespectingIntegers(r.width()); 140 ts << "x" << TextStream::FormatNumberRespectingIntegers(r.height()); 141 141 return ts; 142 142 }
Note: See TracChangeset
for help on using the changeset viewer.