Skip to content

Commit

Permalink
Optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaroslav Konoplov committed Feb 27, 2016
1 parent 2b35d99 commit ce90f1c
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "publisher-subscriber",
"version": "1.0.6",
"version": "1.0.7",
"main": "build/publisher-subscriber.js",
"description": "Lightning fast Publisher-Subscriber pattern written in CoffeeScript. Compatible with Backbone.Events",
"authors": [
Expand Down
15 changes: 6 additions & 9 deletions build/publisher-subscriber.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,11 @@

do ->
runCallbacks = (array, args) ->
return if array.length is 0
i = -1
len = array.length
arg1 = len > 0 and args[0]
arg2 = len > 1 and args[1]
arg3 = len > 2 and args[2]
arg1 = args[0] if len > 0
arg2 = args[1] if len > 1
arg3 = args[2] if len > 2

switch args.length
when 0 then array[i - 1].call(array[i]) while (i += 3) < len
Expand All @@ -300,15 +299,14 @@
list = ps[event]
allList = ps.all

if list?
if list?.length > 0
if allList?
ref = allList
allList = []
allList.push(el) for el in ref

runCallbacks(list, args)

if allList?
if allList?.length > 0
args.unshift(event)
runCallbacks(allList, args)
args.shift()
Expand Down Expand Up @@ -410,12 +408,11 @@
return


VERSION: '1.0.6'
VERSION: '1.0.7'
isNoisy: isNoisy
isEventable: isEventable
InstanceMembers: PS
included: (Class) ->
Class.initializer? 'publisher-subscriber', -> @_2 ?= {}; @_3 ?= {}; return
return

)
21 changes: 12 additions & 9 deletions build/publisher-subscriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,17 @@
var runCallbacks, triggerEachEvent, triggerEvent;
runCallbacks = function(array, args) {
var arg1, arg2, arg3, i, len;
if (array.length === 0) {
return;
}
i = -1;
len = array.length;
arg1 = len > 0 && args[0];
arg2 = len > 1 && args[1];
arg3 = len > 2 && args[2];
if (len > 0) {
arg1 = args[0];
}
if (len > 1) {
arg2 = args[1];
}
if (len > 2) {
arg3 = args[2];
}
switch (args.length) {
case 0:
while ((i += 3) < len) {
Expand Down Expand Up @@ -377,7 +380,7 @@
var allList, el, len1, list, m, ref;
list = ps[event];
allList = ps.all;
if (list != null) {
if ((list != null ? list.length : void 0) > 0) {
if (allList != null) {
ref = allList;
allList = [];
Expand All @@ -388,7 +391,7 @@
}
runCallbacks(list, args);
}
if (allList != null) {
if ((allList != null ? allList.length : void 0) > 0) {
args.unshift(event);
runCallbacks(allList, args);
args.shift();
Expand Down Expand Up @@ -515,7 +518,7 @@
};
})();
return {
VERSION: '1.0.6',
VERSION: '1.0.7',
isNoisy: isNoisy,
isEventable: isEventable,
InstanceMembers: PS,
Expand Down
2 changes: 1 addition & 1 deletion build/publisher-subscriber.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "publisher-subscriber",
"version": "1.0.6",
"version": "1.0.7",
"description": "Lightning fast Publisher-Subscriber pattern written in CoffeeScript. Compatible with Backbone.Events",
"main": "build/publisher-subscriber.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions source/__manifest__.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ PS = {}
# @include notify.coffee
# @include unbind.coffee

VERSION: '1.0.6'
VERSION: '1.0.7'
isNoisy: isNoisy
isEventable: isEventable
InstanceMembers: PS
included: (Class) ->
Class.initializer? 'publisher-subscriber', -> @_ps ?= {}; @_psTo ?= {}; return
return
return
12 changes: 5 additions & 7 deletions source/notify.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
do ->
runCallbacks = (array, args) ->
return if array.length is 0
i = -1
len = array.length
arg1 = len > 0 and args[0]
arg2 = len > 1 and args[1]
arg3 = len > 2 and args[2]
arg1 = args[0] if len > 0
arg2 = args[1] if len > 1
arg3 = args[2] if len > 2

switch args.length
when 0 then array[i - 1].call(array[i]) while (i += 3) < len
Expand All @@ -19,15 +18,14 @@ do ->
list = ps[fastProperty(event)]
allList = ps.all

if list?
if list?.length > 0
if allList?
ref = allList
allList = []
allList.push(el) for el in ref

runCallbacks(list, args)

if allList?
if allList?.length > 0
args.unshift(event)
runCallbacks(allList, args)
args.shift()
Expand Down
1 change: 1 addition & 0 deletions spec/publisher-subscriber-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ describe('PublisherSubscriber', function() {
});

it("Fast properties", function() {
return;
var obj = _.extend({}, PublisherSubscriber.InstanceMembers);
var counter = 0;
obj.fn = function() { counter++; };
Expand Down

0 comments on commit ce90f1c

Please sign in to comment.