<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>
<blockquote type="cite">how did you know?</blockquote>
Telepathy :-D<br>
</p>
<p>
<blockquote type="cite">i just find the code mostly more readable.
</blockquote>
That's probably a matter of taste. "!strcmp(...)" is a very
familiar idiom for every C programmer and I find it perfectly
readable.</p>
<p>
<blockquote type="cite">`!strcmp(flag, "-lib")` is of course fine
(apart from the inverse logic of strcmp), but
`!strcmp(argv[i].a_w.w_symbol->s_name, ">")` is not.
</blockquote>
Sure, but neither is "gensym(">") == argv[i].a_w.w_symbol".</p>
<blockquote type="cite">in this case i would happily swap that for a
slow `(gensym(">") == atom_getsymbol(argv+i))`.
</blockquote>
<p>
For a *single* comparison, it might be more readable for some
people. But if you want to compare against several strings - maybe
even in a loop -, you would naturally save the symbol in a
variable, and then the strcmp() version becomes quite readable,
IMO.<br>
</p>
<div class="moz-cite-prefix">
<blockquote type="cite">all those specific comparisions for "-lib"
are done in loop, so you would probably put the gensym("-lib")
outside of that loop.
</blockquote>
<p>That would work, but I think it's overkill. Also, it would
decrease readability, because you can't immediately see the
actual flag string, but instead only see a variable. Also, the
performance gain would be minimal at best, because the strings
are very short and strcmp() terminates on the first non-matching
character, anyway. <br>
</p>
<p>If you consider that "gensym()" needs to<br>
</p>
<p>1) hash the whole string,</p>
<p>2) do a (fast) table look-up and<br>
</p>
<p>3) iterate over the bucket list and do a strcmp() until it
finds an exact match</p>
<p>you would need a couple of loop iterations to make up for those
extra initial costs and gain any performance benefit.</p>
<p>---<br>
</p>
<p>Anyway, it seem like we're now talking more about readability
than performance (which seemed to be your original concern).</p>
<p>I would say that for "ugly" lines like</p>
<pre>`!strcmp(argv[i].a_w.w_symbol->s_name, ">")`</pre>
<p>saving the string in a local variable would already increase
readability significantly:<br>
</p>
<pre>const char *s = argv[i].a_w.w_symbol->s_name;</pre>
<pre>if (!strcmp(s, ">")) ...
</pre>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">Christof<br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">On 11.03.2021 22:13, IOhannes m zmölnig
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:be528924-9c90-0dbd-85e2-d1f15ce412fb@iem.at">On 3/11/21
9:34 PM, Christof Ressi wrote:
<br>
<blockquote type="cite">
<blockquote type="cite">the main purpose of the the symbol table
is, as i understand it, to make string comparison super-fast
(as there's no need to compare each character but just a
simple address). </blockquote>
It is only fast if both sides are `t_symbol *`, but if one side
includes a call to gensym(), it will be *slower* than a simple
strcmp()!
<br>
<br>
For example,
<br>
<br>
flagsym == gensym("-lib")
<br>
</blockquote>
<br>
<br>
funnily enough, this was exactly the line that triggered my query.
<br>
how did you know? (probably because you checked the background of
my other post)
<br>
<br>
<blockquote type="cite">
<br>
is my all means worse than
<br>
<br>
!strcmp(flag, "-lib")
<br>
</blockquote>
<br>
<br>
well, no. all those specific comparisions for "-lib" are done in
loop, so you would probably put the gensym("-lib") outside of that
loop.
<br>
<br>
<blockquote type="cite">
<br>
First of all, these are not the performance critical parts of Pd
and most of the strings in question are very short, anyway.
<br>
<br>
Secondly, for symbol comparison to make sense, you would have to
create all those symbols upfront and store them somewhere. This
would indeed pollute the symbol table and add many lines of
extra code for no real benefit.
<br>
</blockquote>
<br>
<br>
i just find the code mostly more readable.
<br>
`!strcmp(flag, "-lib")` is of course fine (apart from the inverse
logic of strcmp), but `!strcmp(argv[i].a_w.w_symbol->s_name,
">")` is not.
<br>
in this case i would happily swap that for a slow `(gensym(">")
== atom_getsymbol(argv+i))`.
<br>
<br>
anyhow, most of those symbols (with the exception of the actual
flags), are also Pd-objects, so the symtable pollution shouldn't
really matter.
<br>
<br>
gfsmdrt
<br>
IOhannes
<br>
<br>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
Pd-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Pd-dev@lists.iem.at">Pd-dev@lists.iem.at</a>
<a class="moz-txt-link-freetext" href="https://lists.puredata.info/listinfo/pd-dev">https://lists.puredata.info/listinfo/pd-dev</a>
</pre>
</blockquote>
</body>
</html>