Remix.run Logo
shadowgovt 2 days ago

Regarding the spooky-action-at-a-distance concerns of a `.freeze()` method on dict:

`.freeze()` should probably just return a frozendict instead of in-place mutating the dict, and they should be separate types. Under the hood, you'll have to build the hashtable anyway to make the frozendict; as long as you're doing that work, you may as well build an object to contain the hashtable and just have that object be separate from the dict that birthed it.

The values referenced by both the original dict and the frozendict can be the same values; no need to clone them.

emil-lp a day ago | parent [-]

The point is that freeze could work in constant time, whereas the copying takes linear time.

Another alternative mentioned was `move`, which would create a frozen version in constant time and clear the original dict.

shadowgovt 13 hours ago | parent [-]

Freeze can't work in constant time if it builds a hash when the dict is frozen so that the dict can be used as a key.

If all it does is set a flag that prevents modifications, that's different.