waneck / testrepo

0 stars 0 forks source link

Issue 1242 - Array.indexOf? - haxe #1242

Open waneck opened 11 years ago

waneck commented 11 years ago

[Google Issue #1242 : http://code.google.com/haxe/issues/detail?id=1242] by System.g...@gmail.com, at 2012-10-23T12:31:01.000Z EcmaScript support Array.indexOf. Flash, JS has native methods indexOf lastindexOf

waneck commented 11 years ago

[comment from nad...@gmail.com, published at 2012-10-24T07:24:35.000Z] It's in the Lambda static class. You can add these methods with "using Lambda".

waneck commented 11 years ago

[comment from System.g...@gmail.com, published at 2012-10-24T07:28:08.000Z] I know about Lambda. Lambda.indexOf if very slow in comparation with native method.

waneck commented 11 years ago

[comment from nad...@gmail.com, published at 2012-10-24T19:45:08.000Z] Is it? I thought it works by the same loop algorhithm in original Array

waneck commented 11 years ago

[comment from ncanna...@gmail.com, published at 2012-10-25T16:25:55.000Z] indexOf is not supported everywhere, so we need to generate some additional code in JS output to ensure it will run on old browsers. http://stackoverflow.com/questions/1744310/how-to-fix-array-indexof-in-javascript-for-ie-browsers Now that we have feature selection, we can do it without impacting the runtime size when indexOf is not used.

waneck commented 11 years ago

[comment from ncanna...@gmail.com, published at 2012-10-25T16:26:55.000Z] In that case we might consider adding other recent native methods such as map/iter ?

waneck commented 11 years ago

[comment from stickup...@gmail.com, published at 2012-10-25T16:28:14.000Z] For platforms with indexOf surely this could be done via another using and because the indexOf method is inlined then your code will essentially call the native indexOf method directly.

class Iterables { public inline static function indexOf(itr:Iterable, index : T) : Int {

if (js || flash)

  return (cast itr).indexOf(index);
#else
    return Lambda.indexOf(i);
#end

}

// etc... }

waneck commented 11 years ago

[comment from stickup...@gmail.com, published at 2012-10-25T16:31:13.000Z] Or do what Nicolas said ;-)

waneck commented 11 years ago

[comment from ncanna...@gmail.com, published at 2012-11-16T22:30:33.000Z] All JS 1.6 methods are listed here : https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array

However it seems quite a big work to change all the Array implementation, I'll push it back to post 3.0

waneck commented 11 years ago

[comment from System.g...@gmail.com, published at 2013-02-05T09:23:01.000Z] js Array.indexOf used in HxOverrides http://code.google.com/p/haxe/source/browse/trunk/std/js/_std/HxOverrides.hx#114

why we can't do something like this http://try.haxe.org/#7A0dC in haxe Array?

waneck commented 11 years ago

[comment from si...@haxe.org, published at 2013-02-24T17:12:14.000Z]