1999Q1/
<!-- MHonArc v2.4.4 -->
<!--X-Subject: [MUD&#45;Dev] Re: Question on c++ switch optimization, and parsers in general. -->
<!--X-From-R13: Pra Uerrne <terrneNploreuvtujnl.arg> -->
<!--X-Date: Mon, 8 Feb 1999 22:01:28 &#45;0800 -->
<!--X-Message-Id: 36BFC87C.CAB34DF#cyberhighway,net -->
<!--X-Content-Type: text/plain -->
<!--X-Reference: 199902090329.UAA00854@ami&#45;cg.GraySage.Edmonton.AB.CA -->
<!--X-Reference: 19990208233237.A22601#mesa,Princeton.EDU -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, [MUD-Dev] Re: Question on c++ switch optimization, and parsers</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:greear#cyberhighway,net">
</head>
<body background="/backgrounds/paperback.gif" bgcolor="#ffffff"
      text="#000000" link="#0000FF" alink="#FF0000" vlink="#006000">

  <font size="+4" color="#804040">
    <strong><em>MUD-Dev<br>mailing list archive</em></strong>
  </font>
      
<br>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
<br clear=all><hr>
<!--X-Body-Begin-->
<!--X-User-Header-->
<!--X-User-Header-End-->
<!--X-TopPNI-->

Date:&nbsp;
[&nbsp;<a href="msg00371.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00373.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00369.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00368.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00372">Author</A>
&nbsp;|&nbsp;<A HREF="#00372">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00372">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</H1>
<HR>
<!--X-Subject-Header-End-->
<!--X-Head-of-Message-->
<UL>
<LI><em>To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
<LI><em>Subject</em>: [MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</LI>
<LI><em>From</em>: Ben Greear &lt;<A HREF="mailto:greear#cyberhighway,net">greear#cyberhighway,net</A>&gt;</LI>
<LI><em>Date</em>: Mon, 08 Feb 1999 22:32:44 -0700</LI>
<LI><em>Reply-To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>
Adam J. Thornton wrote:
&gt; 
&gt; On Mon, Feb 08, 1999 at 08:29:46PM -0700, Chris Gray wrote:
&gt; &gt;     - emit an inline table containing offsets to the code to be executed.
&gt; &gt;       Table is directly indexed by a multiple of the switch value,
&gt; &gt;       usually with a range-test to handle the default. A variant is
&gt; &gt;       to have branch instructions in the table, and to branch to
&gt; &gt;       the appropriate one which then branches to the final code.
&gt; 
&gt; The computed GOTO lives!
&gt; 
&gt; My approach would be: write it however it is easiest for you, the author,
&gt; to understand.
&gt; 
&gt; If it turns out to be unacceptably slow, and if profiling the execution
&gt; shows that that *is* the bottleneck (both of which I consider unlikely),
&gt; then think about changing it and worry about how your compiler is doing it.
&gt; 
&gt; Adam
&gt; --
&gt; adam#princeton,edu
&gt; "There's a border to somewhere waiting, and a tank full of time." - J. Steinman

Thanks for all the interesting discussion!

My new plan to do things is this:
Going to write a command spec file, which will contain well-formatted
entries
of aliases, help_keys, and actuall code to satisfy the command.

Then, I'm going to run it through a code-generator to generate c++ code.
A class will be generated for each command, with an execute() command
containing
the actual code mentioned just above.  An instance of each class will be
put
in an array (indexed by an enum, just cause I like enums, and I can
easily
generate one at this point anyway).

So, once I get the enum though what-ever hashing method I come up with,
it will be a simple array-lookup to find the object that knows how to
execute the code.  With my current approach, I expect an average of
10-20
strncasecmp's per command, which I can live with.  I can always optimize
that
down the road, but I'm sure stuff like AI code will drown it anyway.

This (I think, not done yet) arrangement should give me the goals I set
out for:
	*  Easy to add aliases, because I want to make it multi-lingual
eventually.
	*  Quick lookup time.
	*  Help key paired with command so I don't have to edit both in
separate code...
	*  Easy to modify en-masse (through code generation).
	*  I don't have to hand type a bazillion minute classes with one boring
	   method, cause it's generate by magic now!

I will of course publish all this code as soon as it compiles :)

Ben

-- 
Ben Greear (greear#cyberhighway,net)  <A  HREF="http://www.primenet.com/~greear">http://www.primenet.com/~greear</A> 
Author of ScryMUD:  mud.primenet.com 4444        (Released under GPL)
<A  HREF="http://www.primenet.com/~greear/ScryMUD/scry.html">http://www.primenet.com/~greear/ScryMUD/scry.html</A>


</PRE>

<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<HR>
<!--X-Follow-Ups-End-->
<!--X-References-->
<UL><LI><STRONG>References</STRONG>:
<UL>
<LI><STRONG><A NAME="00366" HREF="msg00366.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</A></STRONG>
<UL><LI><EM>From:</EM> Chris Gray &lt;cg#ami-cg,GraySage.Edmonton.AB.CA&gt;</LI></UL></LI>
<LI><STRONG><A NAME="00369" HREF="msg00369.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</A></STRONG>
<UL><LI><EM>From:</EM> "Adam J. Thornton" &lt;adam#phoenix,Princeton.EDU&gt;</LI></UL></LI>
</UL></LI></UL>
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg00371.html">[MUD-Dev] code profiling</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00373.html">[MUD-Dev] optimizing code</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00369.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00368.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00372"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00372"><STRONG>Thread</STRONG></A></LI>
</UL>
</LI>
</UL>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
<ul><li>Thread context:
<BLOCKQUOTE><UL>
<LI><STRONG>[MUD-Dev] optimizing code</STRONG>, <EM>(continued)</EM>
<ul compact>
<LI><strong><A NAME="00373" HREF="msg00373.html">[MUD-Dev] optimizing code</A></strong>, 
diablo <a href="mailto:diablo#best,com">diablo#best,com</a>, Tue 09 Feb 1999, 06:31 GMT
<UL>
<LI><strong><A NAME="00374" HREF="msg00374.html">[MUD-Dev] Re: optimizing code</A></strong>, 
Hans-Henrik Staerfeldt <a href="mailto:hhs#cbs,dtu.dk">hhs#cbs,dtu.dk</a>, Tue 09 Feb 1999, 14:58 GMT
</LI>
</UL>
</LI>
</ul>
</LI>
<LI><strong><A NAME="00366" HREF="msg00366.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</A></strong>, 
Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Tue 09 Feb 1999, 03:31 GMT
<UL>
<LI><strong><A NAME="00369" HREF="msg00369.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</A></strong>, 
Adam J. Thornton <a href="mailto:adam#phoenix,Princeton.EDU">adam#phoenix,Princeton.EDU</a>, Tue 09 Feb 1999, 04:34 GMT
<UL>
<LI><strong><A NAME="00372" HREF="msg00372.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</A></strong>, 
Ben Greear <a href="mailto:greear#cyberhighway,net">greear#cyberhighway,net</a>, Tue 09 Feb 1999, 06:01 GMT
</LI>
</UL>
</LI>
</UL>
<UL>
<li>&lt;Possible follow-up(s)&gt;<br>
<LI><strong><A NAME="00368" HREF="msg00368.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</A></strong>, 
Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Tue 09 Feb 1999, 03:54 GMT
<UL>
<LI><strong><A NAME="00370" HREF="msg00370.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</A></strong>, 
T. Alexander Popiel <a href="mailto:popiel#snugharbor,com">popiel#snugharbor,com</a>, Tue 09 Feb 1999, 04:41 GMT
</LI>
</UL>
</LI>
</UL>
</LI>
<LI><strong><A NAME="00355" HREF="msg00355.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers i</A></strong>, 
Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Mon 08 Feb 1999, 06:11 GMT
<UL>
<li>&lt;Possible follow-up(s)&gt;<br>
<LI><strong><A NAME="00367" HREF="msg00367.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers i</A></strong>, 
Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Tue 09 Feb 1999, 03:45 GMT
</LI>
</UL>
</LI>
</UL></BLOCKQUOTE>

</ul>
<hr>
<center>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
</center>
<hr>
</body>
</html>