Bug 33189 - scaleEmToUnits in SimpleFontDataMac.mm does an unnecessary division
Summary: scaleEmToUnits in SimpleFontDataMac.mm does an unnecessary division
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-01-04 17:01 PST by Ojan Vafai
Modified: 2010-01-04 19:56 PST (History)
1 user (show)

See Also:


Attachments
2010-01-04 Nikolas Zimmermann <nzimmermann@rim.com> (1.05 KB, patch)
2010-01-04 17:36 PST, Ojan Vafai
darin: review-
Details | Formatted Diff | Diff
Remove unnecessary division (1.55 KB, patch)
2010-01-04 17:39 PST, Ojan Vafai
no flags Details | Formatted Diff | Diff
Patch without static_cast. (1.55 KB, patch)
2010-01-04 18:12 PST, Ojan Vafai
no flags Details | Formatted Diff | Diff
Patch without static_cast for real this time. (1.53 KB, patch)
2010-01-04 18:50 PST, Ojan Vafai
mitz: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ojan Vafai 2010-01-04 17:01:14 PST
It's not a big deal, but I stumbled upon it and thought I'd clean it up.

const float contextDPI = 72.0f;
static inline float scaleEmToUnits(float x, unsigned unitsPerEm) { return x * (contextDPI / (contextDPI * unitsPerEm)); }

can just be

static inline float scaleEmToUnits(float x, unsigned unitsPerEm) { return x / static_cast<float>(unitsPerEm); }

Technically, there could be minor differences here due to float rounding I think, but in practice I think this is just an accident of history. The code was added here http://trac.webkit.org/changeset/8104. I assume this was done to match the previously private function, but we don't use that function anymore.

In either case, the layout tests pass with this change.
Comment 1 Ojan Vafai 2010-01-04 17:36:36 PST
Created attachment 45847 [details]
2010-01-04  Nikolas Zimmermann  <nzimmermann@rim.com>
Comment 2 Darin Adler 2010-01-04 17:37:23 PST
Comment on attachment 45847 [details]
2010-01-04  Nikolas Zimmermann  <nzimmermann@rim.com>

Looks like this is the wrong patch.
Comment 3 Ojan Vafai 2010-01-04 17:38:42 PST
Comment on attachment 45847 [details]
2010-01-04  Nikolas Zimmermann  <nzimmermann@rim.com>

Holy cow that was fast. I was just marking this patch obsolete!

Bugzilla-tool post-commits is confusing. head~1 really should be the top commit, not the second one. Sorry for the spam.
Comment 4 Ojan Vafai 2010-01-04 17:39:31 PST
Created attachment 45849 [details]
Remove unnecessary division
Comment 5 Darin Adler 2010-01-04 18:01:48 PST
Comment on attachment 45849 [details]
Remove unnecessary division

> -static inline float scaleEmToUnits(float x, unsigned unitsPerEm) { return x * (contextDPI / (contextDPI * unitsPerEm)); }
> +static inline float scaleEmToUnits(float x, unsigned unitsPerEm) { return x / static_cast<float>(unitsPerEm); }

Why the static_cast<float>? As far as I know, C will do a float / unsigned just fine, and return a float without any cast.
Comment 6 WebKit Review Bot 2010-01-04 18:04:49 PST
style-queue ran check-webkit-style on attachment 45849 [details] without any errors.
Comment 7 Ojan Vafai 2010-01-04 18:12:09 PST
Created attachment 45854 [details]
Patch without static_cast.
Comment 8 Ojan Vafai 2010-01-04 18:13:11 PST
(In reply to comment #5)
> (From update of attachment 45849 [details])
> > -static inline float scaleEmToUnits(float x, unsigned unitsPerEm) { return x * (contextDPI / (contextDPI * unitsPerEm)); }
> > +static inline float scaleEmToUnits(float x, unsigned unitsPerEm) { return x / static_cast<float>(unitsPerEm); }
> 
> Why the static_cast<float>? As far as I know, C will do a float / unsigned just
> fine, and return a float without any cast.

I was just mimicking code used in the other platform's versions of scaleEmToUnits. Removed.
Comment 9 Ojan Vafai 2010-01-04 18:50:23 PST
Created attachment 45856 [details]
Patch without static_cast for real this time.
Comment 10 mitz 2010-01-04 18:58:47 PST
Comment on attachment 45856 [details]
Patch without static_cast for real this time.

> +        Need a short description and bug URL (OOPS!)

Please remove that line.

> +        No new tests. Covered by existing tests.

More like this code change does not change behavior.
Comment 11 Ojan Vafai 2010-01-04 19:56:53 PST
http://trac.webkit.org/changeset/52782