|
ferris Newbie
Joined: 21 Mar 2006 Posts: 2
|
Posted: Tue Mar 21, 2006 8:16 am
Optimization question (replace vs subregex vs ???) |
Hi everyone,
I have a large map created for a mud that I play. Recently I've been
going through my scripts doing optimizing at the largest bottlenecks.
I'm hoping someone can see if there is a better way to optimize the
following. This is an example output from %walk.
.5n3e2s;.(open west;w)2nw;.n;.(open north;n);w;.3n2e;.(say apple);.(say orange)
Now, the mud uses a 'run' command to execute long paths quickly. So
any move > 1 room I use run ns, instead of .ns. I need to convert the
above to a "|" delimited list. So it would look like the following...
run 5n3e2s|open west|w|run 2nw|n|open north|n|w|run 3n2e|say apple|say orange
I currently accomplish this with a nested replace...
#if %begins( @sw_temp, ".(") {#var sw_temp {%right( @sw_temp, 2)}}
#if %ends( @sw_temp, ")") {#var sw_temp {%leftback( @sw_temp, 1)}}
#var sw_temp {%replace( %replace( %replace( %replace( %replace( @sw_temp, ")", "|."), ";.(", "|"), ";", "|"), ".|", ""), ".", "run ")}
I've also tried using subregex, along the lines of ...
#if (!%begins( @sw_temp, ".(") and !%null( @sw_temp)) {#var sw_temp %concat( "run ", @sw_temp)}
#var sw_temp %subregex( %subregex( %subregex( @sw_temp, "\)", "|run "), "\;", "|"), "[\.\(\)]", "")
#if %ends( @sw_temp, "|run ") {#var sw_temp {%leftback( @sw_temp, 5)}}
sw_temp in both cases is just the example %walk output posted above.
During testing I've copied that example onto itself and created a very
large test variable. I've found that using subregex is 3x slower than
the replace method. I figured it would have been faster.
Either way...can anyone think of a better/faster way to accomplish
this task? I've considered creating a custom loop, but just think that
the number of %copy, %concat etc I'd have to do will be overwhelmingly
slower than the replace method.
Is there any known way to change the way %walk formats its output? It
is quite ugly and hard to deal with.
Thanks for your help. |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Tue Mar 21, 2006 11:17 am |
Try %exec.
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
ferris Newbie
Joined: 21 Mar 2006 Posts: 2
|
Posted: Tue Mar 21, 2006 11:34 pm |
Vijilante wrote: |
Try %exec. |
I'm guessing that Vijilante didn't actually read my post and just
commented after reading the 'delimited by |' comment. But I gave it
a shot anyhow...
Just finished a script that applied exec, then rebuilt the string item by
item to the finished product. It is even worse, 6-7 times slower than
the nested replace method. There are simply way too many if, concat
and item calls.
I'm confident now that the replace method is by far the fastest. If
anyone thinks they can do better, go for it. I don't think you can...
*wink wink* |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|