Subject: | Maintain contexts; optimizations |
I have a case where an application works on two libraries
simultaneously, and where each can be configured with its own list of
additional - private - types. This is a bit hard to deal with in the
current implementation of MIME::Types.
MIME::Types maintains only one global list; addType adds to that one
global list.
It would be better if addType maintained the list of additions in the
object; e.g. $self->{addedTypes}{addition} = ...
Then mimeTypeOf (and friends) would check the object first, then the
global list.
This would keep the memory saving of a global list for the pre-compiled
types, but would allow additions to be per-object.
Related: it's expensive to initialize MIME::Types - it spends a lot of
cycles reading and re-indexing the database. And it does it again
whenever an add invalidates the index. Keeping a separate index for
the additions would make re-indexing cheaper, since it would only have
to deal with the additions...
It would also be better if the index (or indexes when the object has
one for the additions) was pointed to by the object. This would allow
an application to save the expense of reading and constructing the list
index for each transaction by serializing and caching the object. (It
can detect updates by caching $MIME::Types::VERSION with the object...)
FWIW,