Prevent CPViewController from loading the same cibs lots of times. I think the solution should be made generic and put into CPCib though. Closes #348.

This commit is contained in:
Ross Boucher
2009-12-01 09:25:49 -08:00
parent f1d4794dd1
commit 1381bb5c54
+9 -10
View File
@@ -22,7 +22,7 @@
@import <AppKit/CPResponder.j>
var _cachedCibs;
var CPViewControllerCachedCibs;
/*! @class CPViewController
The CPViewController class provides the fundamental view-management controller for Cappuccino applications.
@@ -57,6 +57,12 @@ var _cachedCibs;
CPDictionary _cibExternalNameTable @accessors(property=cibExternalNameTable, readonly);
}
+ (void)initialize
{
if (self === CPViewController)
CPViewControllerCachedCibs = [CPDictionary dictionary];
}
/*!
Convenience initializer calls -initWithCibName:bundle: with nil for both parameters.
*/
@@ -114,22 +120,15 @@ var _cachedCibs;
{
if (_view)
return;
// if (_cibName)
// [CPException raise: reason:];
// initialize the dictionary
if (!_cachedCibs)
_cachedCibs = [CPDictionary dictionary];
// check if a cib is already cached for the current _cibName
var cib = [_cachedCibs objectForKey:_cibName];
var cib = [CPViewControllerCachedCibs objectForKey:_cibName];
if (!cib)
{
// if the cib isn't cached yet : fetch it and cache it
cib = [[CPCib alloc] initWithContentsOfURL:[_cibBundle pathForResource:_cibName + @".cib"]];
[_cachedCibs setObject:cib forKey:_cibName];
[CPViewControllerCachedCibs setObject:cib forKey:_cibName];
}
[cib instantiateCibWithExternalNameTable:_cibExternalNameTable];