Author Topic: Item Database  (Read 1013 times)

Code: [Select]
function Database::registerItem(%this, %name, %a, %b, %c, %d, %e, %f, %g, %h, %i, %j, %k, %l, %m, %n, %o, %p, %q)
{
if(%name $= "")
return;

%itemID = %this.getItemCount() + 1;
%this.item[%itemID] = new scriptObject();
%this.item[%itemID].name = %name;
%vars = "abcdefghijklmnopq";
for(%i = 0; %i < strLen(%vars); %i++)
{
%var = eval("return %" @ getSubStr(%vars,%i,1) @ ";");
if(%var !$= "")
eval("%this.item[%itemID]." @ strReplace(firstField(%var), " ", "") SPC "= \"" @ restFields(%var) @ "\";");
}
}

« Last Edit: January 14, 2013, 07:10:38 PM by !Trinick »


Why do all that string manipulation? It seems inefficient.
Instead of using variables like %a, just do something like %var[0], %var[1], %var[2], and then loop through all of them.

Two reasons. One, I wanted to change his code as little as possible. Two, variable insertion is actually less efficient than that string manipulation: this one just grabs a pointer offset and evaluates a line of code, where as variable insertion has to read the value of the variable, calculate it's position in the variable name, fetch the pointer for the new offset, and return that pointer.

Two reasons. One, I wanted to change his code as little as possible. Two, variable insertion is actually less efficient than that string manipulation: this one just grabs a pointer offset and evaluates a line of code, where as variable insertion has to read the value of the variable, calculate it's position in the variable name, fetch the pointer for the new offset, and return that pointer.

............

............
What? Do you need me to go into an entire brown townysis of how both ways grow into assembly commands and provide a step by step brown townysis of speed comparison? Trust me, assembly is my favorite language.

What? Do you need me to go into an entire brown townysis of how both ways grow into assembly commands and provide a step by step brown townysis of speed comparison? Trust me, assembly is my favorite language.

Sure, i can use a good laugh lol.

Sure, i can use a good laugh lol.
Sorry, it was an empty offer. I'm not going to go parse hundreds of lines of assembly code to prove that I'm right. If Torque used proper arrays, that would be faster. However, it doesn't, which adds string calculation steps that slow it down compared to the getSubStr function which simply grabs the character at %i offset since it's of 1 length. The way Torque parses both calls a function for [] too, so there's no speed optimization for the variable insertion.