[whatwg] Canvas 2d methods

Andrew Fedoniouk news at terrainformatica.com
Sun Jul 2 14:10:12 PDT 2006


----- Original Message ----- 
From: "Ian Hickson" <ian at hixie.ch>
To: "Andrew Fedoniouk" <news at terrainformatica.com>
Cc: <vladimir at pobox.com>; "Benjamin Joffe" <canvasgame at gmail.com>; 
<whatwg at whatwg.org>
Sent: Sunday, July 02, 2006 12:59 PM
Subject: Re: [whatwg] Canvas 2d methods


> On Sun, 2 Jul 2006, Andrew Fedoniouk wrote:
>> > On Sat, 1 Jul 2006, Andrew Fedoniouk wrote:
>> > >
>> > > In prototype based languages it is almost impossible to implement
>> > > 'with' effectively in the given notation.
>> > >
>> > > ctx.moveTo(0,0).lineTo(10,10);
>> > >
>> > > is more effective. In some circumstances - in times.
>> >
>> > Why is it more effective for JS?
>>
>> foo.bar()
>>
>> requires lookup only in foo and its proto chain. And
>
> ...for "bar". It still requires a complete lookup for "foo" in all the
> parts of the scope chain.

1) if it is declared as
var foo = something;  in current frame then
foo.bar();
foo.baz();
then execution is quite efficient.

But
with(something)
{
    bar();
    baz();
}

still requires scan of the whole universe in the worst case.

Consider this:

with(ctx)
{
    bar( some_var_name );
}

runtime will scan full chain of ctx for some_var_name. What for?

-------------- 
something.bar().baz() is even more efficient than

var foo = something;
foo.bar();
foo.baz();

(Good bytecode optimizer can make it exactly something.bar().baz() but...)

>> with( foo ) { bar = 1; }
>>
>> and foo does not contain that bar you need to scan whole namespace chain
>> (with case). In short 'with' creates additional level of ambiguity.
>
> This is only the case where you don't know what "foo" will contain. In
> this case what "foo" contains is very explicitly defined.
>

True. But evil is as always in worst cases.

Andrew Fedoniouk.
http://terrainformatica.com




More information about the whatwg mailing list