Bug 96264 - Reuse floating point formatting of TextStream in RenderTreeAsText.cpp
Summary: Reuse floating point formatting of TextStream in RenderTreeAsText.cpp
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Patrick R. Gansterer
URL:
Keywords:
Depends on:
Blocks: 96330
  Show dependency treegraph
 
Reported: 2012-09-10 05:26 PDT by Patrick R. Gansterer
Modified: 2012-09-14 00:09 PDT (History)
8 users (show)

See Also:


Attachments
Patch (2.34 KB, patch)
2012-09-10 05:44 PDT, Patrick R. Gansterer
gyuyoung.kim: commit-queue-
Details | Formatted Diff | Diff
Patch (4.38 KB, patch)
2012-09-10 06:06 PDT, Patrick R. Gansterer
no flags Details | Formatted Diff | Diff
Patch (6.26 KB, patch)
2012-09-11 09:51 PDT, Patrick R. Gansterer
no flags Details | Formatted Diff | Diff
Patch (6.26 KB, patch)
2012-09-11 09:57 PDT, Patrick R. Gansterer
gyuyoung.kim: commit-queue-
Details | Formatted Diff | Diff
Patch (6.41 KB, patch)
2012-09-11 10:04 PDT, Patrick R. Gansterer
no flags Details | Formatted Diff | Diff
Patch (7.12 KB, patch)
2012-09-13 04:03 PDT, Patrick R. Gansterer
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick R. Gansterer 2012-09-10 05:26:09 PDT
Reuse floating point formatting of TextStream in RenderTreeAsText.cpp
Comment 1 Patrick R. Gansterer 2012-09-10 05:44:53 PDT
Created attachment 163100 [details]
Patch
Comment 2 Gyuyoung Kim 2012-09-10 05:57:23 PDT
Comment on attachment 163100 [details]
Patch

Attachment 163100 [details] did not pass efl-ews (efl):
Output: http://queues.webkit.org/results/13796870
Comment 3 Peter Beverloo (cr-android ews) 2012-09-10 05:59:09 PDT
Comment on attachment 163100 [details]
Patch

Attachment 163100 [details] did not pass cr-android-ews (chromium-android):
Output: http://queues.webkit.org/results/13796869
Comment 4 Build Bot 2012-09-10 06:01:03 PDT
Comment on attachment 163100 [details]
Patch

Attachment 163100 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/13800803
Comment 5 Early Warning System Bot 2012-09-10 06:01:16 PDT
Comment on attachment 163100 [details]
Patch

Attachment 163100 [details] did not pass qt-ews (qt):
Output: http://queues.webkit.org/results/13798785
Comment 6 Patrick R. Gansterer 2012-09-10 06:06:27 PDT
Created attachment 163107 [details]
Patch
Comment 7 Benjamin Poulain 2012-09-10 15:23:27 PDT
Comment on attachment 163107 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=163107&action=review

> Source/WebCore/rendering/RenderTreeAsText.cpp:90
> -String formatNumberRespectingIntegers(double value)
> +void writeNumberRespectingIntegers(TextStream& ts, float value)

The change double->float must be justified.

> Source/WebCore/rendering/RenderTreeAsText.cpp:121
> -    ts << "(" << formatNumberRespectingIntegers(p.x());
> -    ts << "," << formatNumberRespectingIntegers(p.y());
> +    ts << "(";
> +    writeNumberRespectingIntegers(ts, p.x());
> +    ts << ",";
> +    writeNumberRespectingIntegers(ts, p.y());
>      ts << ")";
>      return ts;

I haven't looked at this code in detail yet so that is just an early comment.

To make the code more readable, could't you add an operator<< to TextStream taking an wrapper returned by formatNumberRespectingIntegers? Something like this:

struct TextStreamFormatNumberRespectingIntegers { double value; }

TextStream::operator<<(TextStreamFormatNumberRespectingIntegers value) {
    if (hasFractions(value)) {
        ...
}
Comment 8 Patrick R. Gansterer 2012-09-11 09:51:08 PDT
Created attachment 163387 [details]
Patch
Comment 9 WebKit Review Bot 2012-09-11 09:55:56 PDT
Attachment 163387 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebCore/ChangeLog', u'Source/WebCor..." exit_code: 1
Source/WebCore/platform/text/TextStream.h:38:  This { should be at the end of the previous line  [whitespace/braces] [4]
Total errors found: 1 in 5 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 10 Patrick R. Gansterer 2012-09-11 09:57:24 PDT
Created attachment 163390 [details]
Patch
Comment 11 Gyuyoung Kim 2012-09-11 10:01:19 PDT
Comment on attachment 163390 [details]
Patch

Attachment 163390 [details] did not pass efl-ews (efl):
Output: http://queues.webkit.org/results/13818432
Comment 12 WebKit Review Bot 2012-09-11 10:02:47 PDT
Comment on attachment 163390 [details]
Patch

Attachment 163390 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/13806825
Comment 13 Early Warning System Bot 2012-09-11 10:04:11 PDT
Comment on attachment 163390 [details]
Patch

Attachment 163390 [details] did not pass qt-ews (qt):
Output: http://queues.webkit.org/results/13806828
Comment 14 Early Warning System Bot 2012-09-11 10:04:11 PDT
Comment on attachment 163390 [details]
Patch

Attachment 163390 [details] did not pass qt-wk2-ews (qt):
Output: http://queues.webkit.org/results/13826303
Comment 15 Patrick R. Gansterer 2012-09-11 10:04:42 PDT
Created attachment 163394 [details]
Patch
Comment 16 Benjamin Poulain 2012-09-12 14:37:21 PDT
Comment on attachment 163394 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=163394&action=review

I like this, it is a better encapsulation.

> Source/WebCore/ChangeLog:10
> +        RenderTreeAsText uses the same format for streaming out floats as
> +        TextStream does. Replace formatNumberRespectingIntegers() with
> +        a new overload to the operator<< to avoid code duplications.

I would like a bit more explanation.
1) What code duplication is saved.
2) Mention it takes advantage of StringBuilder::appendNumber() to avoid a temporary StringImpl.

> Source/WebCore/platform/text/TextStream.cpp:29
> +#include <math.h>

MathExtras.h for future proofing it?

> Source/WebCore/platform/text/TextStream.cpp:119
> +TextStream& TextStream::operator<<(const FormatNumberRespectingIntegers& value)

value -> formattedValue or something like that?
The following "value.value" is a little unfortunate for readability.

> Source/WebCore/rendering/RenderTreeAsText.h:-102
> -String formatNumberRespectingIntegers(double);
> -

Can you remove 
#include <wtf/MathExtras.h> ?
Comment 17 Patrick R. Gansterer 2012-09-13 04:03:53 PDT
Created attachment 163832 [details]
Patch
Comment 18 Patrick R. Gansterer 2012-09-14 00:09:30 PDT
Committed r128564: <http://trac.webkit.org/changeset/128564>