This project has moved and is read-only. For the latest updates, please go here.

What are the ObjectInstance.*Inline* members for?

Nov 7, 2011 at 5:53 AM
Edited Nov 7, 2011 at 6:00 AM

I noticed that if I call GetPropertyValue or InlineGetPropertyValue, the ObjectInstance returns the same value. Should I use InlineGet/SetPropertyValue when I need to get or set a bunch of properties all at once? I am guessing this is what is meant by Inline.

I figured the following out so far. Not sure what to do with the cache key that I get from InlineGetPropertyValue. Maybe I save that to pass back to InlineSetPropertyValue? But then, why does ObjectInstance also have an InlineCacheKey property?

static class Stuff
{
	static ScriptEngine _se;

	public static void Go()
	{
		_se = new ScriptEngine();

		_se.SetGlobalFunction("AddInt", (Func<int, int, int>)AddInt);
		_se.Execute("var Hi5 = 5;");
		var ir = _se.Evaluate<int>("AddInt(10, Hi5);");
		Debug.Print("ir: {0}", ir);

		var jr = _se.Evaluate<ObjectInstance>(@"(function(){ return {name:'wayne'}; })()");
		Debug.Print("jr.name: {0}", jr.GetPropertyValue("name"));

		int ci; object ck;
		var jrn = jr.InlineGetPropertyValue("name", out ci, out ck);
		Debug.Print("jrn: {0}", jrn);

		jrn = jr.InlinePropertyValues[ci];
		Debug.Print("jrn: {0}", jrn);
	}

	static int AddInt(int a, int b) { return a + b; }
}

Prints:

ir: 15

jr.name: wayne

jrn: wayne

jrn: wayne
Nov 7, 2011 at 10:02 PM

These methods are actually a way of speeding up property access when you are getting/setting the same property multiple times (e.g. in a loop).  These methods are really only intended for internal use and may change in the future (they are only public due to technical limitations), but if you want to learn more, check out the method doc comments: http://jurassic.codeplex.com/SourceControl/changeset/view/04cfa59365b2#Jurassic%2fLibrary%2fObject%2fObjectInstance.cs

Here's an example of how it is used:

int index;
object key = null;
ObjectInstance obj = ...;
while (...)
{
    object value;
    if (key == obj.InlineCacheKey)
        value = obj.InlinePropertyValues[index];
    else
        value = InlineGetPropertyValue("name", out index, out key);
}

Provided no new properties are added to the object, it reduces the work required to get/set a property to a couple of property lookups, a pointer comparison and an array access.

Nov 16, 2011 at 2:24 AM

Thank you.