Re: StringBuilder Extension: IsQuotedBy

Peter Obiefuna <[email protected]> Thu, 14 Feb 2008 09:03:12 -0700
Newsgroups gmane.comp.windows.devel.dotnet.clr
Message-ID <[email protected]>
>> Daniel said: developing complex parsers without regexp isn't for the
>> faint-hearted =)

Do people still do that? And why would anyone want to do that? If you ask me
it will amount to whipping your own home-grown char-snake-and-ladder
"alphabet state machine" AKA a regex engine.

Wouldn't every lexer have to do this to identify tokens? It seems like an
obligatory step for most really big parsing workflows.
P


--------------------------------------------------
From: "Daniel Petersson" <[email protected]>
Sent: Thursday, February 14, 2008 3:31 AM
To: <[email protected]>
Subject: Re: [DOTNET-CLR] StringBuilder Extension: IsQuotedBy

> perf, strings and loops
>
> I have developed a few .NET based parsers during the last few years and
> here are som fast comments:
>
> 1. avoid creating objects, all kinds of objects are "really expensive" to
> create, especially in loops. gc:s generally aren't an issue when parsing,
> unless parsing HUGE documents, a small parser will have completed before
> the gc kicks in.
>
> 2. avoid virtual calls and delegates; both are great for flexibility but
> slows your code down considerably when executed in tight parse-loops.
>
> 3. regexp really rocks if you are looking for flexibilty; in those cases
> where flexibility is more important then speed regexp is really the
> perfect match, but if you are working on a small, well-defined and really
> fast parser don't even think about regexp.
>
> (1), (2) and (3) all trade performance against readability and
> maintainability; I recomend regexp for all "slow" cases but if you really
> are looking for performance it isn't a good solution. If a parse case is
> "slow" or "fast" really depend on your development task, but be adviced,
> developing complex parsers without regexp isn't for the faint-hearted =)
>
> regards,
>  Daniel
>
> ________________________________________
> From: Discussion of development on the .NET platform using any managed
> language [[email protected]] On Behalf Of Brady Kelly
> [[email protected]]
> Sent: Thursday, February 14, 2008 8:58 AM
> To: [email protected]
> Subject: Re: [DOTNET-CLR] StringBuilder Extension: IsQuotedBy
>
> Probably, but I always get uneasy creating strings in loops, and this was
> just the culmination of my paranoia, fuelled by an evil combination of
> caffeine and fatigue.
>
>>
>> Isn't a ToString() with a regexp more efficient?
>>
>>         FB
>>
>> > I was playing around with avoiding, at all costs, creating surplus
>> strings,
>> > and came up with the following method to see if a StringBuilder, that
>> I use
>> > for each of a collection of string fields, is surrounded by a certain
>> > string, e.g. double quotes.  I was just wondering if this is an
>> efficiant
>> > way of doing it:
>> >
>> >
>> >
>> >         public static bool IsQuotedBy(this StringBuilder sb, string
>> > quoteString)
>> >
>> >         {
>> >
>> >             // Check if the first characters match the quote string.
>> >
>> >             for (int i = 0; i < quoteString.Length; i++)
>> >
>> >             {
>> >
>> >                 if (sb[i] != quoteString[i])
>> >
>> >                 {
>> >
>> >                     return false;
>> >
>> >                 }
>> >
>> >             }
>> >
>> >
>> >
>> >             // Check if the last characters match the quote string.
>> >
>> >             for (int i = sb.Length - quoteString.Length; i <
>> sb.Length; i++
>> > )
>> >
>> >             {
>> >
>> >                 int qsIndex = 0;
>> >
>> >                 if (sb[i] != quoteString[qsIndex++])
>> >
>> >                 {
>> >
>> >                     return false;
>> >
>> >                 }
>> >
>> >             }
>> >
>> >
>> >
>> >             return true;
>> >
>> >         }
>
> ===================================
> This list is hosted by DevelopMentor?  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>
> ===================================
> This list is hosted by DevelopMentor®  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com