mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-20 21:49:22 +00:00
Add additional support for dependent keys, some performance improvements.
This commit is contained in:
1 parent
3b82ef5fde
commit
e859e9efc0
2 files changed
+15
-12
No files matched your search
@@ -62,6 +62,12 @@
|
||||
|
||||
+ (CPSet)keyPathsForValuesAffectingValueForKey:(CPString)aKey
|
||||
{
|
||||
var capitalizedKey = aKey.charAt(0).toUpperCase()+aKey.substring(1);
|
||||
selector = "keyPathsForValuesAffectingValueFor"+capitalizedKey;
|
||||
|
||||
if ([[self class] respondsToSelector:selector])
|
||||
return objj_msgSend([self class], selector);
|
||||
|
||||
return [CPSet set];
|
||||
}
|
||||
|
||||
@@ -196,12 +202,12 @@ var KVOProxyMap = [CPDictionary dictionary],
|
||||
if (!composedOfKeys)
|
||||
return;
|
||||
|
||||
var dependentKeysForClass = [DependentKeysMap objectForKey:_nativeClass];
|
||||
var dependentKeysForClass = [DependentKeysMap objectForKey:[_nativeClass hash]];
|
||||
|
||||
if (!dependentKeysForClass)
|
||||
{
|
||||
dependentKeysForClass = [CPDictionary new];
|
||||
[DependentKeysMap setObject:dependentKeysForClass forKey:_nativeClass];
|
||||
[DependentKeysMap setObject:dependentKeysForClass forKey:[_nativeClass hash]];
|
||||
}
|
||||
|
||||
for (var i=0, count=composedOfKeys.length; i<count; i++)
|
||||
@@ -319,7 +325,7 @@ var KVOProxyMap = [CPDictionary dictionary],
|
||||
[observerInfo.observer observeValueForKeyPath:aKey ofObject:_targetObject change:changes context:observerInfo.context];
|
||||
}
|
||||
|
||||
var keysComposedOfKey = [[[DependentKeysMap objectForKey:_nativeClass] objectForKey:aKey] allObjects];
|
||||
var keysComposedOfKey = [[[DependentKeysMap objectForKey:[_nativeClass hash]] objectForKey:aKey] allObjects];
|
||||
|
||||
if (!keysComposedOfKey)
|
||||
return;
|
||||
|
||||
@@ -298,19 +298,19 @@ import <Foundation/CPKeyValueObserving.j>
|
||||
[bob setValue:"initial bob" forKey:"name"];
|
||||
|
||||
var startTime = new Date();
|
||||
|
||||
|
||||
for(var i=0; i<1000; i++)
|
||||
[bob setValue:i+"bob" forKey:"name"];
|
||||
|
||||
|
||||
var total = new Date() - startTime;
|
||||
|
||||
[bob addObserver:[CPObject new] forKeyPath:"name" options:nil context:nil];
|
||||
|
||||
startTime = new Date();
|
||||
|
||||
|
||||
for(var i=0; i<1000; i++)
|
||||
[bob setValue: i+"bob" forKey:"name"];
|
||||
|
||||
|
||||
var secondTotal = new Date() - startTime;
|
||||
|
||||
[self assertTrue: (secondTotal < total*4) message: "Overheard of one observer exceeded 400%. first: "+total+" second: "+secondTotal+" %"+FLOOR(secondTotal/total*100)];
|
||||
@@ -458,12 +458,9 @@ import <Foundation/CPKeyValueObserving.j>
|
||||
CarTester car;
|
||||
}
|
||||
|
||||
+ (CPSet)keyPathsForValuesAffectingValueForKey:(CPString)aKey
|
||||
+ (CPSet)keyPathsForValuesAffectingValueForBobName
|
||||
{
|
||||
if (aKey == "bobName")
|
||||
return [CPSet setWithObject:"name"];
|
||||
else
|
||||
return [[super class] keyPathsForValuesAffectingValueForKey:aKey];
|
||||
return [CPSet setWithObject:"name"];
|
||||
}
|
||||
|
||||
- (void)setName:(CPString)aName
|
||||
|
||||
Reference in new issue
Block a user