{"action":"created","comment":{"url":"https://api.github.com/repos/Leaflet/Leaflet/pulls/comments/69585675","id":69585675,"diff_hunk":"@@ -90,95 +90,116 @@ L.Evented = L.Class.extend({\n \r\n \t// attach listener (without syntactic sugar now)\r\n \t_on: function (type, fn, context) {\r\n+\t\tthis._events = this._events || {};\r\n+\r\n+\t\t/* get/init listeners for type */\r\n+\t\tvar typeListeners = this._events[type];\r\n+\t\tif (!typeListeners) {\r\n+\t\t\ttypeListeners = {\r\n+\t\t\t\tlisteners: {},\r\n+\t\t\t\tfnIndices: {},\r\n+\t\t\t\tcount: 0\r\n+\t\t\t};\r\n+\t\t\tthis._events[type] = typeListeners;\r\n+\t\t}\r\n \r\n-\t\tvar events = this._events = this._events || {},\r\n-\t\t    contextId = context && context !== this && L.stamp(context);\r\n-\r\n-\t\tif (contextId) {\r\n-\t\t\t// store listeners with custom context in a separate hash (if it has an id);\r\n-\t\t\t// gives a major performance boost when firing and removing events (e.g. on map object)\r\n-\r\n-\t\t\tvar indexKey = type + '_idx',\r\n-\t\t\t    indexLenKey = type + '_len',\r\n-\t\t\t    typeIndex = events[indexKey] = events[indexKey] || {},\r\n-\t\t\t    id = L.stamp(fn) + '_' + contextId;\r\n-\r\n-\t\t\tif (!typeIndex[id]) {\r\n-\t\t\t\ttypeIndex[id] = {fn: fn, ctx: context};\r\n+\t\tvar contextId = context && context !== this && L.stamp(context),\r\n+\t\t    newListener = {fn: fn, ctx: context};\r\n \r\n-\t\t\t\t// keep track of the number of keys in the index to quickly check if it's empty\r\n-\t\t\t\tevents[indexLenKey] = (events[indexLenKey] || 0) + 1;\r\n-\t\t\t}\r\n+\t\tif (!contextId) {\r\n+\t\t\tcontextId = 'no_context';\r\n+\t\t\tnewListener.ctx = undefined;\r\n+\t\t}\r\n \r\n-\t\t} else {\r\n-\t\t\t// individual layers mostly use \"this\" for context and don't fire listeners too often\r\n-\t\t\t// so simple array makes the memory footprint better while not degrading performance\r\n+\t\t// fn array for context\r\n+\t\tvar listeners = typeListeners.listeners[contextId],\r\n+\t\t    fnIndices = typeListeners.fnIndices[contextId];\r\n+\t\tif (!listeners) {\r\n+\t\t\tlisteners = [];\r\n+\t\t\tfnIndices = {};\r\n+\t\t\ttypeListeners.listeners[contextId] = listeners;\r\n+\t\t\ttypeListeners.fnIndices[contextId] = fnIndices;\r\n+\t\t}\r\n \r\n-\t\t\tevents[type] = events[type] || [];\r\n-\t\t\tevents[type].push({fn: fn});\r\n+\t\t// check if fn already there\r\n+\t\tvar fnStamp = L.stamp(fn);\r\n+\t\tif (fnIndices[fnStamp]) {\r","path":"src/core/Events.js","position":59,"original_position":59,"commit_id":"952cc1dce4cf4c1c4dc2b98f9194659c1d178e40","original_commit_id":"952cc1dce4cf4c1c4dc2b98f9194659c1d178e40","user":{"login":"yohanboniface","id":146023,"avatar_url":"https://avatars.githubusercontent.com/u/146023?v=3","gravatar_id":"","url":"https://api.github.com/users/yohanboniface","html_url":"https://github.com/yohanboniface","followers_url":"https://api.github.com/users/yohanboniface/followers","following_url":"https://api.github.com/users/yohanboniface/following{/other_user}","gists_url":"https://api.github.com/users/yohanboniface/gists{/gist_id}","starred_url":"https://api.github.com/users/yohanboniface/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yohanboniface/subscriptions","organizations_url":"https://api.github.com/users/yohanboniface/orgs","repos_url":"https://api.github.com/users/yohanboniface/repos","events_url":"https://api.github.com/users/yohanboniface/events{/privacy}","received_events_url":"https://api.github.com/users/yohanboniface/received_events","type":"User","site_admin":false},"body":"If indice=0, this will be falsy ;)","created_at":"2016-07-05T15:38:56Z","updated_at":"2016-07-05T15:38:56Z","html_url":"https://github.com/Leaflet/Leaflet/pull/4709#discussion_r69585675","pull_request_url":"https://api.github.com/repos/Leaflet/Leaflet/pulls/4709","_links":{"self":{"href":"https://api.github.com/repos/Leaflet/Leaflet/pulls/comments/69585675"},"html":{"href":"https://github.com/Leaflet/Leaflet/pull/4709#discussion_r69585675"},"pull_request":{"href":"https://api.github.com/repos/Leaflet/Leaflet/pulls/4709"}}},"pull_request":{"url":"https://api.github.com/repos/Leaflet/Leaflet/pulls/4709","id":76293666,"html_url":"https://github.com/Leaflet/Leaflet/pull/4709","diff_url":"https://github.com/Leaflet/Leaflet/pull/4709.diff","patch_url":"https://github.com/Leaflet/Leaflet/pull/4709.patch","issue_url":"https://api.github.com/repos/Leaflet/Leaflet/issues/4709","number":4709,"state":"open","locked":false,"title":"Refactor events futher for even more performance (continuing #2755 and #4697)","user":{"login":"perliedman","id":1246614,"avatar_url":"https://avatars.githubusercontent.com/u/1246614?v=3","gravatar_id":"","url":"https://api.github.com/users/perliedman","html_url":"https://github.com/perliedman","followers_url":"https://api.github.com/users/perliedman/followers","following_url":"https://api.github.com/users/perliedman/following{/other_user}","gists_url":"https://api.github.com/users/perliedman/gists{/gist_id}","starred_url":"https://api.github.com/users/perliedman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/perliedman/subscriptions","organizations_url":"https://api.github.com/users/perliedman/orgs","repos_url":"https://api.github.com/users/perliedman/repos","events_url":"https://api.github.com/users/perliedman/events{/privacy}","received_events_url":"https://api.github.com/users/perliedman/received_events","type":"User","site_admin":false},"body":"This adds bookkeeping of added listener functions to avoid looping over listeners to check existence.\r\n\r\nIn our synthetic tests (`debug/tests/event-perf.html`) it shows almost the same performance as current `master` for `on` and `off`, but keeps the more than double performance for `fire` from #4697.\r\n","created_at":"2016-07-05T15:25:28Z","updated_at":"2016-07-05T15:38:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ef18e7b2fd835a34345901a4c57a819160dedb4a","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Leaflet/Leaflet/pulls/4709/commits","review_comments_url":"https://api.github.com/repos/Leaflet/Leaflet/pulls/4709/comments","review_comment_url":"https://api.github.com/repos/Leaflet/Leaflet/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Leaflet/Leaflet/issues/4709/comments","statuses_url":"https://api.github.com/repos/Leaflet/Leaflet/statuses/952cc1dce4cf4c1c4dc2b98f9194659c1d178e40","head":{"label":"Leaflet:event-refactor-round-2","ref":"event-refactor-round-2","sha":"952cc1dce4cf4c1c4dc2b98f9194659c1d178e40","user":{"login":"Leaflet","id":2854298,"avatar_url":"https://avatars.githubusercontent.com/u/2854298?v=3","gravatar_id":"","url":"https://api.github.com/users/Leaflet","html_url":"https://github.com/Leaflet","followers_url":"https://api.github.com/users/Leaflet/followers","following_url":"https://api.github.com/users/Leaflet/following{/other_user}","gists_url":"https://api.github.com/users/Leaflet/gists{/gist_id}","starred_url":"https://api.github.com/users/Leaflet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Leaflet/subscriptions","organizations_url":"https://api.github.com/users/Leaflet/orgs","repos_url":"https://api.github.com/users/Leaflet/repos","events_url":"https://api.github.com/users/Leaflet/events{/privacy}","received_events_url":"https://api.github.com/users/Leaflet/received_events","type":"Organization","site_admin":false},"repo":{"id":931135,"name":"Leaflet","full_name":"Leaflet/Leaflet","owner":{"login":"Leaflet","id":2854298,"avatar_url":"https://avatars.githubusercontent.com/u/2854298?v=3","gravatar_id":"","url":"https://api.github.com/users/Leaflet","html_url":"https://github.com/Leaflet","followers_url":"https://api.github.com/users/Leaflet/followers","following_url":"https://api.github.com/users/Leaflet/following{/other_user}","gists_url":"https://api.github.com/users/Leaflet/gists{/gist_id}","starred_url":"https://api.github.com/users/Leaflet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Leaflet/subscriptions","organizations_url":"https://api.github.com/users/Leaflet/orgs","repos_url":"https://api.github.com/users/Leaflet/repos","events_url":"https://api.github.com/users/Leaflet/events{/privacy}","received_events_url":"https://api.github.com/users/Leaflet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Leaflet/Leaflet","description":" :leaves: JavaScript library for mobile-friendly interactive maps","fork":false,"url":"https://api.github.com/repos/Leaflet/Leaflet","forks_url":"https://api.github.com/repos/Leaflet/Leaflet/forks","keys_url":"https://api.github.com/repos/Leaflet/Leaflet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Leaflet/Leaflet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Leaflet/Leaflet/teams","hooks_url":"https://api.github.com/repos/Leaflet/Leaflet/hooks","issue_events_url":"https://api.github.com/repos/Leaflet/Leaflet/issues/events{/number}","events_url":"https://api.github.com/repos/Leaflet/Leaflet/events","assignees_url":"https://api.github.com/repos/Leaflet/Leaflet/assignees{/user}","branches_url":"https://api.github.com/repos/Leaflet/Leaflet/branches{/branch}","tags_url":"https://api.github.com/repos/Leaflet/Leaflet/tags","blobs_url":"https://api.github.com/repos/Leaflet/Leaflet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Leaflet/Leaflet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Leaflet/Leaflet/git/refs{/sha}","trees_url":"https://api.github.com/repos/Leaflet/Leaflet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Leaflet/Leaflet/statuses/{sha}","languages_url":"https://api.github.com/repos/Leaflet/Leaflet/languages","stargazers_url":"https://api.github.com/repos/Leaflet/Leaflet/stargazers","contributors_url":"https://api.github.com/repos/Leaflet/Leaflet/contributors","subscribers_url":"https://api.github.com/repos/Leaflet/Leaflet/subscribers","subscription_url":"https://api.github.com/repos/Leaflet/Leaflet/subscription","commits_url":"https://api.github.com/repos/Leaflet/Leaflet/commits{/sha}","git_commits_url":"https://api.github.com/repos/Leaflet/Leaflet/git/commits{/sha}","comments_url":"https://api.github.com/repos/Leaflet/Leaflet/comments{/number}","issue_comment_url":"https://api.github.com/repos/Leaflet/Leaflet/issues/comments{/number}","contents_url":"https://api.github.com/repos/Leaflet/Leaflet/contents/{+path}","compare_url":"https://api.github.com/repos/Leaflet/Leaflet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Leaflet/Leaflet/merges","archive_url":"https://api.github.com/repos/Leaflet/Leaflet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Leaflet/Leaflet/downloads","issues_url":"https://api.github.com/repos/Leaflet/Leaflet/issues{/number}","pulls_url":"https://api.github.com/repos/Leaflet/Leaflet/pulls{/number}","milestones_url":"https://api.github.com/repos/Leaflet/Leaflet/milestones{/number}","notifications_url":"https://api.github.com/repos/Leaflet/Leaflet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Leaflet/Leaflet/labels{/name}","releases_url":"https://api.github.com/repos/Leaflet/Leaflet/releases{/id}","deployments_url":"https://api.github.com/repos/Leaflet/Leaflet/deployments","created_at":"2010-09-22T16:57:44Z","updated_at":"2016-07-05T15:32:12Z","pushed_at":"2016-07-05T15:25:28Z","git_url":"git://github.com/Leaflet/Leaflet.git","ssh_url":"git@github.com:Leaflet/Leaflet.git","clone_url":"https://github.com/Leaflet/Leaflet.git","svn_url":"https://github.com/Leaflet/Leaflet","homepage":"http://leafletjs.com","size":49493,"stargazers_count":14089,"watchers_count":14089,"language":"JavaScript","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":true,"forks_count":2578,"mirror_url":null,"open_issues_count":277,"forks":2578,"open_issues":277,"watchers":14089,"default_branch":"master"}},"base":{"label":"Leaflet:master","ref":"master","sha":"c263f2d8b1bd962b60474376cc4816a688052513","user":{"login":"Leaflet","id":2854298,"avatar_url":"https://avatars.githubusercontent.com/u/2854298?v=3","gravatar_id":"","url":"https://api.github.com/users/Leaflet","html_url":"https://github.com/Leaflet","followers_url":"https://api.github.com/users/Leaflet/followers","following_url":"https://api.github.com/users/Leaflet/following{/other_user}","gists_url":"https://api.github.com/users/Leaflet/gists{/gist_id}","starred_url":"https://api.github.com/users/Leaflet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Leaflet/subscriptions","organizations_url":"https://api.github.com/users/Leaflet/orgs","repos_url":"https://api.github.com/users/Leaflet/repos","events_url":"https://api.github.com/users/Leaflet/events{/privacy}","received_events_url":"https://api.github.com/users/Leaflet/received_events","type":"Organization","site_admin":false},"repo":{"id":931135,"name":"Leaflet","full_name":"Leaflet/Leaflet","owner":{"login":"Leaflet","id":2854298,"avatar_url":"https://avatars.githubusercontent.com/u/2854298?v=3","gravatar_id":"","url":"https://api.github.com/users/Leaflet","html_url":"https://github.com/Leaflet","followers_url":"https://api.github.com/users/Leaflet/followers","following_url":"https://api.github.com/users/Leaflet/following{/other_user}","gists_url":"https://api.github.com/users/Leaflet/gists{/gist_id}","starred_url":"https://api.github.com/users/Leaflet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Leaflet/subscriptions","organizations_url":"https://api.github.com/users/Leaflet/orgs","repos_url":"https://api.github.com/users/Leaflet/repos","events_url":"https://api.github.com/users/Leaflet/events{/privacy}","received_events_url":"https://api.github.com/users/Leaflet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Leaflet/Leaflet","description":" :leaves: JavaScript library for mobile-friendly interactive maps","fork":false,"url":"https://api.github.com/repos/Leaflet/Leaflet","forks_url":"https://api.github.com/repos/Leaflet/Leaflet/forks","keys_url":"https://api.github.com/repos/Leaflet/Leaflet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Leaflet/Leaflet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Leaflet/Leaflet/teams","hooks_url":"https://api.github.com/repos/Leaflet/Leaflet/hooks","issue_events_url":"https://api.github.com/repos/Leaflet/Leaflet/issues/events{/number}","events_url":"https://api.github.com/repos/Leaflet/Leaflet/events","assignees_url":"https://api.github.com/repos/Leaflet/Leaflet/assignees{/user}","branches_url":"https://api.github.com/repos/Leaflet/Leaflet/branches{/branch}","tags_url":"https://api.github.com/repos/Leaflet/Leaflet/tags","blobs_url":"https://api.github.com/repos/Leaflet/Leaflet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Leaflet/Leaflet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Leaflet/Leaflet/git/refs{/sha}","trees_url":"https://api.github.com/repos/Leaflet/Leaflet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Leaflet/Leaflet/statuses/{sha}","languages_url":"https://api.github.com/repos/Leaflet/Leaflet/languages","stargazers_url":"https://api.github.com/repos/Leaflet/Leaflet/stargazers","contributors_url":"https://api.github.com/repos/Leaflet/Leaflet/contributors","subscribers_url":"https://api.github.com/repos/Leaflet/Leaflet/subscribers","subscription_url":"https://api.github.com/repos/Leaflet/Leaflet/subscription","commits_url":"https://api.github.com/repos/Leaflet/Leaflet/commits{/sha}","git_commits_url":"https://api.github.com/repos/Leaflet/Leaflet/git/commits{/sha}","comments_url":"https://api.github.com/repos/Leaflet/Leaflet/comments{/number}","issue_comment_url":"https://api.github.com/repos/Leaflet/Leaflet/issues/comments{/number}","contents_url":"https://api.github.com/repos/Leaflet/Leaflet/contents/{+path}","compare_url":"https://api.github.com/repos/Leaflet/Leaflet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Leaflet/Leaflet/merges","archive_url":"https://api.github.com/repos/Leaflet/Leaflet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Leaflet/Leaflet/downloads","issues_url":"https://api.github.com/repos/Leaflet/Leaflet/issues{/number}","pulls_url":"https://api.github.com/repos/Leaflet/Leaflet/pulls{/number}","milestones_url":"https://api.github.com/repos/Leaflet/Leaflet/milestones{/number}","notifications_url":"https://api.github.com/repos/Leaflet/Leaflet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Leaflet/Leaflet/labels{/name}","releases_url":"https://api.github.com/repos/Leaflet/Leaflet/releases{/id}","deployments_url":"https://api.github.com/repos/Leaflet/Leaflet/deployments","created_at":"2010-09-22T16:57:44Z","updated_at":"2016-07-05T15:32:12Z","pushed_at":"2016-07-05T15:25:28Z","git_url":"git://github.com/Leaflet/Leaflet.git","ssh_url":"git@github.com:Leaflet/Leaflet.git","clone_url":"https://github.com/Leaflet/Leaflet.git","svn_url":"https://github.com/Leaflet/Leaflet","homepage":"http://leafletjs.com","size":49493,"stargazers_count":14089,"watchers_count":14089,"language":"JavaScript","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":true,"forks_count":2578,"mirror_url":null,"open_issues_count":277,"forks":2578,"open_issues":277,"watchers":14089,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Leaflet/Leaflet/pulls/4709"},"html":{"href":"https://github.com/Leaflet/Leaflet/pull/4709"},"issue":{"href":"https://api.github.com/repos/Leaflet/Leaflet/issues/4709"},"comments":{"href":"https://api.github.com/repos/Leaflet/Leaflet/issues/4709/comments"},"review_comments":{"href":"https://api.github.com/repos/Leaflet/Leaflet/pulls/4709/comments"},"review_comment":{"href":"https://api.github.com/repos/Leaflet/Leaflet/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Leaflet/Leaflet/pulls/4709/commits"},"statuses":{"href":"https://api.github.com/repos/Leaflet/Leaflet/statuses/952cc1dce4cf4c1c4dc2b98f9194659c1d178e40"}}}}
{"actor":{"display_login":"yohanboniface"}}