Re: NS_NewArrayEnumerator
Benjamin Smedberg wrote: On 12/18/2012 11:05 AM, Neil wrote: While looking at tbsaunde's patch to remove the nsISupportsArray version of NS_NewArrayEnumerator I noticed that many users of NS_NewArrayEnumerator copy entries from a hash into a temporary array which they then enumerate, which works by creating an instance of an enumerator class that recopies the entries from the temporary array. Would it make sense to create an array enumerator class that was preallocated to a given capacity and then filled directly? The API would look like this (error checking omitted for clarity): nsCOMEnumerator* result = NS_NewCOMEnumerator(mHash.entryCount); HashTableEnumerate(mHash, AppendElementToEnumerator, result); aResult = result; Is this specific to maps becoming enumerators, and could we just make that API specifically? No, because consumers generally store arbitrary structures in their hashes which happen to contain a COM object. You could also just have an enumerator which adopts a nsCOMArray_base or a nsTArray. This still needs an allocation for the enumerator itself, although I guess you could move the elements to the enumerator instead of copying them. -- Warning: May contain traces of nuts. ___ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform
NS_NewArrayEnumerator
While looking at tbsaunde's patch to remove the nsISupportsArray version of NS_NewArrayEnumerator I noticed that many users of NS_NewArrayEnumerator copy entries from a hash into a temporary array which they then enumerate, which works by creating an instance of an enumerator class that recopies the entries from the temporary array. Would it make sense to create an array enumerator class that was preallocated to a given capacity and then filled directly? The API would look like this (error checking omitted for clarity): nsCOMEnumerator* result = NS_NewCOMEnumerator(mHash.entryCount); HashTableEnumerate(mHash, AppendElementToEnumerator, result); aResult = result; -- Warning: May contain traces of nuts. ___ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform
Re: NS_NewArrayEnumerator
On 12/18/2012 11:05 AM, Neil wrote: While looking at tbsaunde's patch to remove the nsISupportsArray version of NS_NewArrayEnumerator I noticed that many users of NS_NewArrayEnumerator copy entries from a hash into a temporary array which they then enumerate, which works by creating an instance of an enumerator class that recopies the entries from the temporary array. Would it make sense to create an array enumerator class that was preallocated to a given capacity and then filled directly? The API would look like this (error checking omitted for clarity): nsCOMEnumerator* result = NS_NewCOMEnumerator(mHash.entryCount); HashTableEnumerate(mHash, AppendElementToEnumerator, result); aResult = result; Is this specific to maps becoming enumerators, and could we just make that API specifically? I don't mind this API. You could also just have an enumerator which adopts a nsCOMArray_base or a nsTArray. --BDS ___ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform