-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: spec: keys/vals function for map types #7057
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
There is no way to avoid allocation if you want to convert a map's keys to a slice of keys, since the map does not store its keys in a slice. You could write a version of these functions today using the reflect package. Other than that I don't think this is a likely extension, but it is a possible one so I'll leave it open for now. Labels changed: added release-none, repo-main, languagechange. |
I think what Ian is saying is that your keys() and vals() operations necessarily need to make a copy, as the underlying data isn't laid out as a slice. So while such ops would make your job syntactically simpler, the underlying implementation wouldn't be any simpler (it would create the same garbage either way). There might be less garbage if the keys were large and keys(m) returned a slice of pointers to keys. |
This is similar to other requests for builtin generic functionality, such as map/reduce #14173. Otherwise keys/values could be implemented or generated for each map type desired. |
Any implementation of these functions has to make a copy, so there is no way to generate less garbage than the hand written implementation. We aren't going to do this special case. Closing. |
The text was updated successfully, but these errors were encountered: