On Dec 11, 2006, at 3:12 PM, Theodore H. Smith wrote:

From: Charles Yeomans <[EMAIL PROTECTED]>
Date: Sun, 10 Dec 2006 16:38:46 -0500


On Dec 10, 2006, at 12:40 PM, Theodore H. Smith wrote:

From: William Squires <[EMAIL PROTECTED]>
Date: Sat, 9 Dec 2006 18:54:23 -0600

Oops, I guess I misread the intent of the original line; I thought you were just checking to see if the line could be a number, and were
interested in a more efficient way to quickly test it without a lot
of overhead. And, actually, the 'quickie' test with Asc will even
allow you to put comments after the number in the file, whereas the
original call to IsNumber() would - I believe - fail if there were
extra non-numeric characters after the 1st numeric character, so:

1 // <- translates to 'Case 1'

would pass with the Asc() test, but would fail on the IsNumber() test
(I think - I haven't actually tried it myself.) Of course, I didn't
try the perl test either; not being a perl fan myself.
   Granted, this approach, while allowing comments, doesn't
necessarily define what the comment character is!


With ElfData, the code would be:

if line.OutCharSet(numbers) = 0 then
// it's a number
else
// text
end

It's actually quite simple code.

the "numbers" variable, you init earlier, like this:

numbers = "0123456789"

This creates a 256 byte lookup table in RAM, making for scanning of
strings of any character set, very fast.

The same approach is possible with REALbasic, but it won't have C
compiler optimisations, and will have a lot of method call overhead.

Why is that?  I've always found array access to be reasonably fast.

Well, it will be fast, but not that fast.

It should take 1 instruction to read a byte from a string and increment the pointer.

It should take 1 more instruction to load the boolean from the table using the byte as the lookup index.

So that's 2 instructions to get the bool.

I think REALbasic will take more than 2 instructions to do something like this:

dim b as boolean

b = MyArray( ascb( midb( s, i, 1 ) ) )

Maybe more like 500 instructions.

Perhaps, but I wouldn't do it that way.

Charles Yeomans


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to