HaxeFoundation/haxe — pull request #3455 by SmerkyG (2014-10-08 20:59:36+00:00)
Title: Stringmap unification

Unified flash `StringMap` and `UnsafeStringMap`, which no longer need to be distinct since Nicolas optimized away the `hasOwnProperty` call. `StringMap` becomes significantly optimized with this change, removing memory allocs for the "$" prepending. It also fixes a problem where `StringMap` and `UnsafeStringMap` returned different kinds of null values. (See issue #3454) Also deprecated `UnsafeStringMap`, per suggestion by @nadako

Rationale: `Dictionary` allows safe access of strings like `"constructor"` and `"prototype"` using `[]` syntax. The `hasOwnProperty` call was probably an issue earlier, because it could have looked for the prototype property on the dictionary object instead of its `"prototype"` key for example. But since `StringMap` uses `__in__` now, this should not be a problem. I tested it against setting, testing for existence of, removing, and iterating keys of `"constructor"` and `"prototype"` and came up against no problems.

Regarding the different null value returns, there was a case where the inlined `get()` method on `UnsafeStringMap` would return flash's `undefined` value instead of `null`. This caused strange and inconsistent behavior between `StringMap` and `UnsafeStringMap` on flash target. For example, the `Null` return value from `get()` for a nonexistent entry when compared to a real `Int` would be different on `StringMap` and `UnsafeStringMap`. This implementation checks the result and ensures that `null` and not `undefined` is returned, while still allowing inlining.