[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in [NSScanner scanDouble:]

From: Richard Frith-Macdonald
Subject: Re: Bug in [NSScanner scanDouble:]
Date: Wed, 30 Dec 2020 12:56:28 +0000

> On 29 Dec 2020, at 09:32, Fred Kiefer <fredkiefer@gmx.de> wrote:
>  The code in NSScanner should have the correct implementation and 
> GSScanDouble should  just call that. This solution would require to allocate 
> and free an NSScanner object, and I am pretty sure that Richard wouldn’t like 
> the extra time spend on that.

Well I came to the conclusion that you were right to say that the -scanDouble: 
method of NSScanner needs the correct implementation.  This is mostly because a 
valid double can have a huge number of leading zeros, and can also have more 
precision digits than the double supports (OSX ignores excess precision and 
leading zeros).  It also means that everywhere the code was calling 
GSScanDouble() in NSString.m was incorrect (because the calling code was 
copying stuff into a buffer which might be too small).

So, I got rid of the function altogether, and added a private method that 
NSString can use to scan a double with less overhead (avoiding the 
creation/destruction of the NSScanner instance.  I hope performance is good 
enough: I think it should be, as I also made a small optimisation for scanning 
strings using the 8bit internal representation, which ought to speed up the 
most common case.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]