Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 15 in printed book and digital formats -- plus a one-year subscription so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview

Buy Now



Optimizing Parsing Code

I feel the need. The need for speed.

Issue: 9.5 (July/August 2011)
Author: Brendan Murphy
Article Description: No description available.
Article Length (in bytes): 7,200
Starting Page Number: 27
RBD Number: 9506
Resource File(s):

Download Icon 9506.zip Updated: Tuesday, July 5, 2011 at 11:15 AM

Related Web Link(s):


Known Limitations: None

Excerpt of article text...

A while back I implemented an optimization in my RTFParser for the Formatted Text Control which resulted in an overall measured speed increase of 33%! This optimization mainly applies to situations of parsing, but it can be applied to other scenarios if certain conditions are met.

Let's say you have a select statement in your code like the following.

select case token

case "alligator"

Do something specific...

case "birds"

Do something specific...

case "cheetah"

Do something specific...


end select

A series of string comparisons are taking place to determine what to do with the token and it will take on average N / 2 comparisons to locate the correct code to execute (where N is the number of cases in the select statement). As the number of cases grows, so does the time it takes to locate the proper case and the more the select statement acts like a boat anchor slowing your program.

The answer is to replace the select-case statement with a mechanism that will find the proper case in a fixed amount of time independent of the number of cases. The components that allow you to do that are delegates, the AddressOf operator, and dictionaries. So let's look at the components of this optimization.

...End of Excerpt. Please purchase the magazine to read the full article.

Article copyrighted by REALbasic Developer magazine. All rights reserved.




Weblog Commenting and Trackback by HaloScan.com