From: Michael G Schwern Date: Sun, 24 Feb 2008 07:20:41 +0000 (-0800) Subject: Greatly speed up result_source_instance() and all the many things which X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=654f330d2c7dfc79b9109ec4b99bba477e9db3ca;p=dbsrgits%2FDBIx-Class-Historic.git Greatly speed up result_source_instance() and all the many things which use it by eliminating the calls to $self->result_class. --- diff --git a/lib/DBIx/Class/DB.pm b/lib/DBIx/Class/DB.pm index 93d7ea6..eadb5ad 100644 --- a/lib/DBIx/Class/DB.pm +++ b/lib/DBIx/Class/DB.pm @@ -150,34 +150,26 @@ Returns an instance of the result source for this class =cut +__PACKAGE__->mk_classdata('_result_source_instance' => []); + sub result_source_instance { my $class = shift; $class = ref $class || $class; - - __PACKAGE__->mk_classdata(qw/_result_source_instance/) - unless __PACKAGE__->can('_result_source_instance'); - - return $class->_result_source_instance(@_) if @_; + return $class->_result_source_instance([$_[0], $class]) if @_; - my $source = $class->_result_source_instance; + my($source, $result_class) = @{$class->_result_source_instance}; return unless Scalar::Util::blessed($source); - if ($source->result_class ne $class) { - # Remove old source instance so we dont get deep recursion - #$DB::single = 1; - # Need to set it to a non-undef value so that it doesn't just fallback to - # a parent class's _result_source_instance - #$class->_result_source_instance({}); - #$class->table($class); - #$source = $class->_result_source_instance; + if ($result_class ne $class) { # new class + # Give this new class it's own source and register it. $source = $source->new({ %$source, source_name => $class, result_class => $class } ); - $class->_result_source_instance($source); + $class->_result_source_instance([$source, $class]); if (my $coderef = $class->can('schema_instance')) { $coderef->($class)->register_class($class, $class); }