mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
This change adds `withValue` templates for the `Table` type that are able to operate on immutable table values -- the existing implementation requires a `var`. This is needed for situations where performance is sensitive. There are two goals with my implementation: 1. Don't create a copy of the value in the table. That's why I need the `cursor` pragma. Otherwise, it would copy the value 2. Don't double calculate the hash. That's kind of intrinsic with this implementation. But the only way to achieve this without this PR is to first check `if key in table` then to read `table[key]` I brought this up in the discord and a few folks tried to come up with options that were as fast as this, but nothing quite matched the performance here. Thread starts here: https://discord.com/channels/371759389889003530/371759389889003532/1355206546966974584