minitest-metadata performance improvements

This PR improves performance of minitest-metadata metadata processing by up to 50%.  See this gist: https://gist.github.com/tmertens/9a3355c3c9a04d537a34

The two caveats here are:

- It requires any hash metadata to appear at the end of the argument list, but this conforms to standard ruby practices.

- If a hash metadata appears at the end of the metadata argument list, other metadata args will be added to that hash rather than instantiating a new hash.  This change is based on the expectation that metadata is generally applied to each method individually and not to two or more methods using a single stored variable.  This gives an additional 25-30% performance boost to metadata args which include a hash.

I have never seen variables used for metadata hashes in the wild myself, but if this is an issue, the second commit can be easily reverted.
:+1:

2014-09-25 20:23 GMT+02:00 Tim Mertens <notifications@github.com>:

> In lib/minitest/metadata.rb:
>
> > @@ -2,7 +2,7 @@ module MiniTest::Metadata
> >    module ClassMethods
> >      # Returns Hash metadata for class' test methods
> >      def metadata
> > -      @metadata ||= {}
> > +      @metadata ||= Hash.new({})
>
> This fixes the spec assertion:
>
> @cls.metadata["test_0002_test2"].must_equal({})
>
> which tests the return value of metadata[key] on the test class itself,
> which previously was always {} for tests with no metadata.
>
> Now that we skip the metadata processor if there is no metadata, there
> would be no key in the metadata hash for a test which was defined with no
> metadata and return nil. By assigning a default value for missing keys in
> the hash, it both fixes the test, does not impact performance, and the
> metadata hash is also faster because it won't have a bunch of unnecessary
> keys with empty hashes for tests without metadata.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/wojtekmach/minitest-metadata/pull/11/files#r18049785>.
>



-- 
Wojtek Mach