@@ -561,34 +561,38 @@ struct LayerFactory::Impl : public std::map<String, LayerFactory::Constuctor>
561
561
{
562
562
};
563
563
564
- // allocates on load and cleans on exit
565
- Ptr<LayerFactory::Impl> LayerFactory::impl (new LayerFactory::Impl());
564
+ Ptr<LayerFactory::Impl> LayerFactory::impl ()
565
+ {
566
+ // allocate on first use
567
+ static Ptr<LayerFactory::Impl> impl_ (new LayerFactory::Impl ());
568
+ return impl_;
569
+ }
566
570
567
571
void LayerFactory::registerLayer (const String &_type, Constuctor constructor)
568
572
{
569
573
String type = _type.toLowerCase ();
570
- Impl::iterator it = impl->find (type);
574
+ Impl::iterator it = impl () ->find (type);
571
575
572
- if (it != impl->end () && it->second != constructor)
576
+ if (it != impl () ->end () && it->second != constructor)
573
577
{
574
578
CV_Error (cv::Error::StsBadArg, " Layer \" " + type + " \" already was registered" );
575
579
}
576
580
577
- impl->insert (std::make_pair (type, constructor));
581
+ impl () ->insert (std::make_pair (type, constructor));
578
582
}
579
583
580
584
void LayerFactory::unregisterLayer (const String &_type)
581
585
{
582
586
String type = _type.toLowerCase ();
583
- impl->erase (type);
587
+ impl () ->erase (type);
584
588
}
585
589
586
590
Ptr<Layer> LayerFactory::createLayerInstance (const String &_type, LayerParams& params)
587
591
{
588
592
String type = _type.toLowerCase ();
589
- Impl::const_iterator it = LayerFactory::impl->find (type);
593
+ Impl::const_iterator it = LayerFactory::impl () ->find (type);
590
594
591
- if (it != impl->end ())
595
+ if (it != impl () ->end ())
592
596
{
593
597
return it->second (params);
594
598
}
0 commit comments