Skip to content

Commit

Permalink
Coat tailed CPEvents on native DOM events if they exist, saving the c…
Browse files Browse the repository at this point in the history
…reation of many objects.

Reviewed by me.
  • Loading branch information
Francisco Ryan Tolmasky I committed May 31, 2009
1 parent 1224ca9 commit f4b4d38
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 21 deletions.
26 changes: 25 additions & 1 deletion AppKit/CPEvent.j
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ var _CPEventPeriodicEventPeriod = 0,
unsigned _clickCount;
float _pressure;
CPWindow _window;
Number _windowNumber;
CPString _characters;
CPString _charactersIgnoringModifiers
BOOL _isARepeat;
Expand Down Expand Up @@ -327,7 +328,7 @@ var _CPEventPeriodicEventPeriod = 0,
_charactersIgnoringModifiers = unmodCharacters;
_isARepeat = isARepeat;
_keyCode = code;
_window = [CPApp windowWithWindowNumber:aWindowNumber];
_windowNumber = aWindowNumber;
}

return self;
Expand Down Expand Up @@ -397,6 +398,9 @@ var _CPEventPeriodicEventPeriod = 0,
*/
- (CPWindow)window
{
if (!_window)
_window = [CPApp windowWithWindowNumber:_windowNumber];

return _window;
}

Expand Down Expand Up @@ -532,3 +536,23 @@ function _CPEventFirePeriodEvent()
[CPApp sendEvent:[CPEvent otherEventWithType:CPPeriodic location:_CGPointMakeZero() modifierFlags:0 timestamp:0 windowNumber:0 context:nil subtype:0 data1:0 data2:0]];
}

var CPEventClass = [CPEvent class];

function _CPEventFromNativeMouseEvent(aNativeEvent, anEventType, aPoint, modifierFlags, aTimestamp, aWindowNumber, aGraphicsContext, anEventNumber, aClickCount, aPressure)
{
aNativeEvent.isa = CPEventClass;

aNativeEvent._type = anEventType;
aNativeEvent._location = aPoint;
aNativeEvent._modifierFlags = modifierFlags;
aNativeEvent._timestamp = aTimestamp;
aNativeEvent._windowNumber = aWindowNumber;
aNativeEvent._window = nil;
aNativeEvent._context = aGraphicsContext;
aNativeEvent._eventNumber = anEventNumber;
aNativeEvent._clickCount = aClickCount;
aNativeEvent._pressure = aPressure;

return aNativeEvent;
}

12 changes: 0 additions & 12 deletions Foundation/CPArray.j
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,6 @@
return self;
}

/*!
Returns a hash of the CPArray.
@return an unsigned integer hash
*/
- (unsigned)hash
{
if (self.__address == nil)
self.__address = _objj_generateObjectHash();

return self.__address;
}

// Querying an array
/*!
Returns <code>YES</code> if the array contains <code>anObject</code>. Otherwise, it returns <code>NO</code>.
Expand Down
2 changes: 1 addition & 1 deletion Foundation/CPNumber.j
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ var __placeholder = new Number(),
return anUnsignedShort;
}

- (CPString)hash
- (CPString)UID
{
if (!_CPNumberHashes[self])
_CPNumberHashes[self] = _objj_generateObjectHash();
Expand Down
8 changes: 8 additions & 0 deletions Foundation/CPObject.j
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,14 @@ CPLog(@"Got some class: %@", inst);</pre>
*/
- (unsigned)hash
{
return [self UID];
}

- (unsigned)UID
{
if (typeof self.__address === "undefined")
self.__address = _objj_generateObjectHash();

return __address;
}

Expand Down
2 changes: 1 addition & 1 deletion Foundation/CPString.j
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ var CPStringRegexSpecialCharacters = [
/*!
Returns a hash of the string instance.
*/
- (unsigned)hash
- (unsigned)UID
{
var hash = dictionary_getValue(CPStringHashes, self);

Expand Down
9 changes: 3 additions & 6 deletions Objective-J/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,12 +472,9 @@ function objj_msgSend(/*id*/ aReceiver, /*SEL*/ aSelector)

switch(arguments.length)
{
case 2:
return implementation(aReceiver, aSelector);
case 3:
return implementation(aReceiver, aSelector, arguments[2]);
case 4:
return implementation(aReceiver, aSelector, arguments[2], arguments[3]);
case 2: return implementation(aReceiver, aSelector);
case 3: return implementation(aReceiver, aSelector, arguments[2]);
case 4: return implementation(aReceiver, aSelector, arguments[2], arguments[3]);
}

return implementation.apply(aReceiver, arguments);
Expand Down

0 comments on commit f4b4d38

Please sign in to comment.