scala/scala — pull request #2033 by adriaanm (2013-01-31 06:21:21+00:00)
Title: pattern matching efficiency: addresses SI-6686 and SI-6941

- don't do null check when we know we've just done a type test
- don't store subpatterns bound to underscore in local val
- note 1: under -optimize this is only done when correctness mandates it for mutable fields
- note 2: mutable fields in case classes nested in the scala package are assumed not to be mutated by public methods, so that we don't have to store them (specifically for ::)
- eliminate local vals storing subpatterns when the vals aren't referenced (their rhs's side-effect is not guaranteed anyway, and normally not observable)
- eliminate primitive value class type test when we statically know it can't fail
- test all this at the bytecode level by comparing bytecode of a match and the equivalent if/then/else/isInstanceOf/asInstanceOf/equals/...

review by @gkossakowski, @retronym