No, `Array.from` never produces a holey array whatsoever; only ever a dense array.
On Sun, Feb 9, 2020 at 11:08 PM Andrea Giammarchi < [email protected]> wrote: > Unfortunately, `Array.from({ length: 4 }, () => whatever)` produces a > holey array, so that the `.repeat(...)` idea, if capable of packing > elements in a better way, wouldn't be so terrible, as simplification. > > Although, the intent of this proposal was to also grant "shapes" or > kindness of each entry, same way typed Arrays do, but maybe that would > require some better primitive, as in `const Shape = > Object.defineShape(...)` and `Object.createShape(Shape)` or similar. > > On Sun, Feb 9, 2020 at 10:01 PM Jordan Harband <[email protected]> wrote: > >> That already exists - `Array.from({ length: 4 }, () => whatever)` - I >> assume that the hope is to have an array where it is *impossible* for it to >> have the wrong "kind" of data, and a userland factory function wouldn't >> provide that. >> >> On Sun, Feb 9, 2020 at 10:39 AM kai zhu <[email protected]> wrote: >> >>> > It's a bit of a mess to create an Array that is not holed and gets >>> best optimizations [1], and this proposal would like to address that exact >>> case. >>> >>> could the performance issue be resolved more easily with a simple >>> static-function `Array.repeat(<length>, <repeater>)`? >>> >>> ```js >>> let structuredList; >>> structuredList = Array.repeat(4, function (ii) { >>> return { >>> index: 2 * ii + 1, >>> tags: [] >>> }); >>> /* >>> structuredList = [ >>> { index: 1, tags: [] }, >>> { index: 3, tags: [] }, >>> { index: 5, tags: [] }, >>> { index: 7, tags: [] } >>> ]; >>> */ >>> ``` >>> >>> the only time i can practically enforce the shape of a "StructuredArray" >>> is during element-insertion, >>> and a userland insertion/creation function would be just as effective as >>> a StructuredArray constructor. >>> >>> enforcing shapes during element deletions and updates are going to be >>> hard >>> and likely just as confusing with StructuredArray as they are with >>> regular Array. >>> >>> also note that most javascript arrays need to be easily JSON-serialized >>> for message-passing >>> over-the-wire (commonly http) to external systems. >>> >>> -kai >>> >>> On Sat, Feb 8, 2020 at 3:46 AM Andrea Giammarchi < >>> [email protected]> wrote: >>> >>>> > having to retroactively add checks like... >>>> >>>> we already have typed arrays in JS so I don't think this would be any >>>> different >>>> >>>> > I _think_ that moderns virtual machines already did these >>>> optimisations despite there isn't a TypedArray like that. >>>> >>>> It's a bit of a mess to create an Array that is not holed and gets best >>>> optimizations [1], and this proposal would like to address that exact case. >>>> >>>> [1] https://v8.dev/blog/elements-kinds >>>> >>>> >>>> >>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> [email protected] >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>> _______________________________________________ >>> es-discuss mailing list >>> [email protected] >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

