Closed
Bug 165877
Opened 22 years ago
Closed 22 years ago
ns[C]String::ToFloat broken. Will never report bad number.
Categories
(Core :: XPCOM, defect)
Core
XPCOM
Tracking
()
RESOLVED
FIXED
mozilla1.3alpha
People
(Reporter: bratell, Assigned: bratell)
Details
(Keywords: perf)
Attachments
(1 file)
2.57 KB,
patch
|
jag+mozilla
:
review+
alecf
:
superreview+
|
Details | Diff | Splinter Review |
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.1b) Gecko/20020317
Build Identifier:
nsString::ToFloat is broken. It will never report a bad number. See this part of
function:
if (*cp != 0) {
*aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE;
}
*aErrorCode = (PRInt32) NS_OK;
return f;
obviously aErrorCode is always NS_OK.
I looked at from a performace view though. Why are we using our own PR_strtod
anyway?
Reproducible: Always
Steps to Reproduce:
Assignee | ||
Updated•22 years ago
|
Status: UNCONFIRMED → NEW
Ever confirmed: true
Assignee | ||
Comment 1•22 years ago
|
||
That goes for both nsString and nsCString.
Summary: nsString::ToFloat broken. Will never report bad number. → ns[C]String::ToFloat broken. Will never report bad number.
Assignee | ||
Comment 2•22 years ago
|
||
This is a rewrite of the functions that do report the error. It also uses
strtod instead of PR_strtod since strtod is faster. PR_strtod had some locking
overhead that I thing is the reason it was slow. When measured in Quantify the
change was a speedup from 26 us/call to 18 us/call (us=microseconds).
I'm looking for r= and sr= on this.
Assignee | ||
Comment 3•22 years ago
|
||
Taking the bug.
Comment 4•22 years ago
|
||
It looks like the old ToFloat code doesn't free the copies it makes. In your new
code, you don't free the result of ToCString.
I don't know why we're using PR_strtod instead of strtod. The only reason I can
think of is that at the time strtod didn't do everywhere what it should, or it
gives different results per platform when we want the same result everywhere.
scc (e-mail him) and dougt might know more about this.
Assignee | ||
Comment 5•22 years ago
|
||
ToCString doesn't allocate. It uses the buffer passed to it so there is no
memory leak since we pass a stack buffer.
I've tried to see why we use PR_strtod and as far as I can tell it's just
because we always have. The PR_strtod is one of David Gay's routines from 1991
and I think it was adopted to run in other environments then Mozilla use today.
Also, we already use the C library's strtod in libpng without any known problems
to me. But I too would like to hear what scc has to say about it.
Comment 6•22 years ago
|
||
Heh, I knew I was missing something, it just wouldn't have made sense if that
old code was leaky.
Assignee | ||
Updated•22 years ago
|
Attachment #97383 -
Flags: superreview?(alecf)
Attachment #97383 -
Flags: review?(jaggernaut)
Comment 7•22 years ago
|
||
Comment on attachment 97383 [details] [diff] [review]
Rewrite of ToFloat
hmm.. is strtod() portable and reliable on all platforms? I'm not sure the
value I see in switching away from PR_strtod()
Assignee | ||
Comment 8•22 years ago
|
||
See comment 2 about the reason to use strtod instead of PR_strtod. The function
strtod is in ANSI C and should be available everywhere. Maybe it was missing 10
years ago on some platform Netscape considered important and that's why it's in
NSPR, but I see no reason to use PR_strtod today.
Comment 9•22 years ago
|
||
Note that libpng has a strtod wrapper around wcstod for WinCE:
http://lxr.mozilla.org/seamonkey/source/modules/libimg/png/pngrutil.c#17
Comment 10•22 years ago
|
||
Comment on attachment 97383 [details] [diff] [review]
Rewrite of ToFloat
I'll bet wince is a unique case, since I'll bet many of the platforms it runs
on (ARM, etc) don't have floating point units.
Assignee | ||
Comment 11•22 years ago
|
||
Does that mean that I can get a positive review of the code? jag? alecf?
Updated•22 years ago
|
Attachment #97383 -
Flags: review?(jaggernaut) → review+
Comment 12•22 years ago
|
||
Comment on attachment 97383 [details] [diff] [review]
Rewrite of ToFloat
sr=alecf
Attachment #97383 -
Flags: superreview?(alecf) → superreview+
Assignee | ||
Comment 13•22 years ago
|
||
Fix checked in
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
Target Milestone: mozilla1.2alpha → mozilla1.3alpha
Comment 14•22 years ago
|
||
This caused bug 183211; not quite sure why yet.
The problem is that you moved to using a locale-sensitive libc function. (And
given that it's locale-sensitive, I doubt that it's faster. Did you measure?)
Assignee | ||
Comment 16•22 years ago
|
||
Yes, I measured, see comment #2. Then again, strtod on Windows (where I do my
tests) doesn't seem to be sensitive to locale so the performance situation may
be different on other platforms.
Thanks for the quick fix!
Updated•4 years ago
|
Component: String → XPCOM
You need to log in
before you can comment on or make changes to this bug.
Description
•