Jump to content

[SOLVED] Maps, append vs []


photo

Recommended Posts

Hello!

 

I am new to Unigine and I am currently going through the UnigineScript documentation. Something that struck me is that I can not see a big difference between appending to a map and just setting a value. The documentation seems to recommend using append when inserting new values, so I am wondering if they are different in some way, maybe something regrading performance? Or perhaps it is just standard convention.

 

What I mean is what is the difference between doing:

int mymap[];
mymap["foo"] = "bar";

and:

int mymap[];
mymap.append("foo", "bar");

The first one seems to me like it's more concise than the second one. The behaviour does not seem to differ really, because when a key already exists, append overwrites the value, so therefor it should (?) work the exact same way as [].

 

Cheers!

Link to comment

Greetings, sir!

 

They do similar things so no difference at all on script level. However, on asm level there's a little difference (pop values instead of calling function).

 

Disassemble for first sample:

0x000036db: pushc      int: -1
0x000036dd: calluac    map1
0x000036df: pushc      string: "bar"
0x000036e1: popuavc    map1[string: "foo"]

And for second sample:

0x000036e4: pushc      int: -1
0x000036e6: calluac    map2
0x000036e8: pushcc     string: "bar" string: "foo"
0x000036eb: calluafr   map2.append

I guess first sample is a little bit faster but nothing to worry about. Use any style you want. On Oil Rush we used 'append'-way a lot.

Link to comment

Hey unclebob!

 

Thanks for your answer! :)

 

That cleared it up, I assume the first one must be faster because a function call gets added to the stack? Anyways I am glad that the method I prefer is faster. However, maybe there can be some advantage to using the function way simply because it calls a function (it would show up in stack traces etc).

 

What tool did you use to disassemble? usc?

 

Cheers!

Link to comment

Hi Isak,

 

To see disassemble of UnigineScript you can type 'world_disassemble <filename>' in console and it'll save world script disassemble to specified file. For system and editor scripts you can use 'system_disassemble' and 'editor_disassemble' console commands.

Link to comment
×
×
  • Create New...