{"action":"created","comment":{"url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/pulls/comments/75592486","id":75592486,"diff_hunk":"@@ -49,58 +32,74 @@ JsonPath.prototype.getValue = function() {\n  * @param {Mixed} value\n  *\n  * @public\n- * @returns {void}\n+ * @returns updated value\n  */\n-JsonPath.prototype.setValue = function( value ) {\n-\tvar node = this._record._$data,\n-\t\ti;\n+module.exports.set = function( data, path, value, deepCopy ) {\n+\tvar tokens = tokenize( path );\n+\n+\tif ( deepCopy !== false ) {\n+\t\tvalue = utils.deepCopy( value );\n+\t}\n \n-\tfor( i = 0; i < this._tokens.length - 1; i++ ) {\n-\t\tif( node[ this._tokens[ i ] ] !== undefined ) {\n-\t\t\tnode = node[ this._tokens[ i ] ];\n+\tif ( tokens.length === 0 ) {\n+\t\treturn value;\n+\t}\n+\n+\tdata = utils.shallowCopy( data );\n+\n+\tvar node = data;\n+\tfor( var i = 0; i < tokens.length; i++ ) {\n+\t\tif ( i === tokens.length - 1) {\n+\t\t\tnode[ tokens[ i ] ] = value;\n \t\t}\n-\t\telse if( this._tokens[ i + 1 ] && !isNaN( this._tokens[ i + 1 ] ) ){\n-\t\t\tnode = node[ this._tokens[ i ] ] = [];\n+\t\telse if( node[ tokens[ i ] ] !== undefined ) {\n+\t\t\tnode = node[ tokens[ i ] ] = utils.shallowCopy( node[ tokens[ i ] ] );\n+\t\t}\n+\t\telse if( tokens[ i + 1 ] && !isNaN( tokens[ i + 1 ] ) ){\n+\t\t\tnode = node[ tokens[ i ] ] = [];\n \t\t}\n \t\telse {\n-\t\t\tnode = node[ this._tokens[ i ] ] = {};\n+\t\t\tnode = node[ tokens[ i ] ] = Object.create( null );\n \t\t}\n \t}\n \n-\tnode[ this._tokens[ i ] ] = value;\n+\treturn data;\n };\n \n /**\n  * Parses the path. Splits it into\n  * keys for objects and indices for arrays.\n  *\n- * @private\n- * @returns {void}\n+ * @returns Array of tokens\n  */\n-JsonPath.prototype._tokenize = function() {\n-\tvar parts = this._path.split( SPLIT_REG_EXP ),\n-\t\tpart,\n-\t\ti;\n+function tokenize( path ) {\n+\tif ( cache[ path ] ) {\n+\t\treturn cache[ path ];\n+\t}\n \n-\tfor( i = 0; i < parts.length; i++ ) {\n-\t\tpart = utils.trim( parts[ i ] );\n+\tvar parts = path !== undefined ? path.toString().split( SPLIT_REG_EXP ) : [];\n+\n+\tvar tokens = [];\n+\n+\tfor( var i = 0; i < parts.length; i++ ) {\n+\t\tvar part = utils.trim( parts[ i ] );\n ","path":"src/record/json-path.js","position":125,"original_position":125,"commit_id":"345b5576818acf9929b37fdb70b4c206213fcbb0","original_commit_id":"345b5576818acf9929b37fdb70b4c206213fcbb0","user":{"login":"ronag","id":3065230,"avatar_url":"https://avatars.githubusercontent.com/u/3065230?v=3","gravatar_id":"","url":"https://api.github.com/users/ronag","html_url":"https://github.com/ronag","followers_url":"https://api.github.com/users/ronag/followers","following_url":"https://api.github.com/users/ronag/following{/other_user}","gists_url":"https://api.github.com/users/ronag/gists{/gist_id}","starred_url":"https://api.github.com/users/ronag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ronag/subscriptions","organizations_url":"https://api.github.com/users/ronag/orgs","repos_url":"https://api.github.com/users/ronag/repos","events_url":"https://api.github.com/users/ronag/events{/privacy}","received_events_url":"https://api.github.com/users/ronag/received_events","type":"User","site_admin":false},"body":"Then I would suggest a `paths.replace(/\\s/g, '')` instead of doing it for each part.","created_at":"2016-08-21T09:51:35Z","updated_at":"2016-08-21T09:51:35Z","html_url":"https://github.com/deepstreamIO/deepstream.io-client-js/pull/214#discussion_r75592486","pull_request_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/pulls/214","_links":{"self":{"href":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/pulls/comments/75592486"},"html":{"href":"https://github.com/deepstreamIO/deepstream.io-client-js/pull/214#discussion_r75592486"},"pull_request":{"href":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/pulls/214"}}},"pull_request":{"url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/pulls/214","id":81789589,"html_url":"https://github.com/deepstreamIO/deepstream.io-client-js/pull/214","diff_url":"https://github.com/deepstreamIO/deepstream.io-client-js/pull/214.diff","patch_url":"https://github.com/deepstreamIO/deepstream.io-client-js/pull/214.patch","issue_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/issues/214","number":214,"state":"open","locked":false,"title":"Optimise & Refactor Records","user":{"login":"ronag","id":3065230,"avatar_url":"https://avatars.githubusercontent.com/u/3065230?v=3","gravatar_id":"","url":"https://api.github.com/users/ronag","html_url":"https://github.com/ronag","followers_url":"https://api.github.com/users/ronag/followers","following_url":"https://api.github.com/users/ronag/following{/other_user}","gists_url":"https://api.github.com/users/ronag/gists{/gist_id}","starred_url":"https://api.github.com/users/ronag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ronag/subscriptions","organizations_url":"https://api.github.com/users/ronag/orgs","repos_url":"https://api.github.com/users/ronag/repos","events_url":"https://api.github.com/users/ronag/events{/privacy}","received_events_url":"https://api.github.com/users/ronag/received_events","type":"User","site_admin":false},"body":"I know that currently this is not something that will get into deepstream but I would at least ask you to consider it, and possibly give some feedback, since we need it.\r\n\r\nOur application is very record heavy and we have some problems with keeping stable 60 fps. We've already improved on this issue with #200 but we still have some performance issues.\r\n\r\nA part form general refactoring and simplification:\r\n\r\nOptimizations:\r\n\r\n- Optional deep copies. Assume immutability.\r\n- Cache path tokenisation.\r\n- Reduced allocations.\r\n- Reduced copies.\r\n\r\nFixes #172, #213\r\n\r\nWe could make even more use of `Object.create( null )` over `{}` for jsonPath. However, jasmine test for types in `isEqual` which would make some tests fail.","created_at":"2016-08-18T10:08:06Z","updated_at":"2016-08-21T09:51:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5bec42ecb128beb57a9d78da100fc5d41986d94e","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/pulls/214/commits","review_comments_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/pulls/214/comments","review_comment_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/pulls/comments{/number}","comments_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/issues/214/comments","statuses_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/statuses/345b5576818acf9929b37fdb70b4c206213fcbb0","head":{"label":"nxtedition:feature/optimize-records","ref":"feature/optimize-records","sha":"345b5576818acf9929b37fdb70b4c206213fcbb0","user":{"login":"nxtedition","id":16840296,"avatar_url":"https://avatars.githubusercontent.com/u/16840296?v=3","gravatar_id":"","url":"https://api.github.com/users/nxtedition","html_url":"https://github.com/nxtedition","followers_url":"https://api.github.com/users/nxtedition/followers","following_url":"https://api.github.com/users/nxtedition/following{/other_user}","gists_url":"https://api.github.com/users/nxtedition/gists{/gist_id}","starred_url":"https://api.github.com/users/nxtedition/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nxtedition/subscriptions","organizations_url":"https://api.github.com/users/nxtedition/orgs","repos_url":"https://api.github.com/users/nxtedition/repos","events_url":"https://api.github.com/users/nxtedition/events{/privacy}","received_events_url":"https://api.github.com/users/nxtedition/received_events","type":"Organization","site_admin":false},"repo":{"id":60109021,"name":"deepstream.io-client-js","full_name":"nxtedition/deepstream.io-client-js","owner":{"login":"nxtedition","id":16840296,"avatar_url":"https://avatars.githubusercontent.com/u/16840296?v=3","gravatar_id":"","url":"https://api.github.com/users/nxtedition","html_url":"https://github.com/nxtedition","followers_url":"https://api.github.com/users/nxtedition/followers","following_url":"https://api.github.com/users/nxtedition/following{/other_user}","gists_url":"https://api.github.com/users/nxtedition/gists{/gist_id}","starred_url":"https://api.github.com/users/nxtedition/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nxtedition/subscriptions","organizations_url":"https://api.github.com/users/nxtedition/orgs","repos_url":"https://api.github.com/users/nxtedition/repos","events_url":"https://api.github.com/users/nxtedition/events{/privacy}","received_events_url":"https://api.github.com/users/nxtedition/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nxtedition/deepstream.io-client-js","description":"The Browser / Node Client for deepstream.io","fork":true,"url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js","forks_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/forks","keys_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/teams","hooks_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/hooks","issue_events_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/issues/events{/number}","events_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/events","assignees_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/assignees{/user}","branches_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/branches{/branch}","tags_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/tags","blobs_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/statuses/{sha}","languages_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/languages","stargazers_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/stargazers","contributors_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/contributors","subscribers_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/subscribers","subscription_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/subscription","commits_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/contents/{+path}","compare_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/merges","archive_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/downloads","issues_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/issues{/number}","pulls_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/pulls{/number}","milestones_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/milestones{/number}","notifications_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/labels{/name}","releases_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/releases{/id}","deployments_url":"https://api.github.com/repos/nxtedition/deepstream.io-client-js/deployments","created_at":"2016-05-31T17:18:52Z","updated_at":"2016-05-31T17:18:54Z","pushed_at":"2016-08-20T20:54:38Z","git_url":"git://github.com/nxtedition/deepstream.io-client-js.git","ssh_url":"git@github.com:nxtedition/deepstream.io-client-js.git","clone_url":"https://github.com/nxtedition/deepstream.io-client-js.git","svn_url":"https://github.com/nxtedition/deepstream.io-client-js","homepage":null,"size":1151,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"deepstreamIO:master","ref":"master","sha":"54f06a93e308130b0b6d4788d0e8cc4d32fff61f","user":{"login":"deepstreamIO","id":9024218,"avatar_url":"https://avatars.githubusercontent.com/u/9024218?v=3","gravatar_id":"","url":"https://api.github.com/users/deepstreamIO","html_url":"https://github.com/deepstreamIO","followers_url":"https://api.github.com/users/deepstreamIO/followers","following_url":"https://api.github.com/users/deepstreamIO/following{/other_user}","gists_url":"https://api.github.com/users/deepstreamIO/gists{/gist_id}","starred_url":"https://api.github.com/users/deepstreamIO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deepstreamIO/subscriptions","organizations_url":"https://api.github.com/users/deepstreamIO/orgs","repos_url":"https://api.github.com/users/deepstreamIO/repos","events_url":"https://api.github.com/users/deepstreamIO/events{/privacy}","received_events_url":"https://api.github.com/users/deepstreamIO/received_events","type":"Organization","site_admin":false},"repo":{"id":27365380,"name":"deepstream.io-client-js","full_name":"deepstreamIO/deepstream.io-client-js","owner":{"login":"deepstreamIO","id":9024218,"avatar_url":"https://avatars.githubusercontent.com/u/9024218?v=3","gravatar_id":"","url":"https://api.github.com/users/deepstreamIO","html_url":"https://github.com/deepstreamIO","followers_url":"https://api.github.com/users/deepstreamIO/followers","following_url":"https://api.github.com/users/deepstreamIO/following{/other_user}","gists_url":"https://api.github.com/users/deepstreamIO/gists{/gist_id}","starred_url":"https://api.github.com/users/deepstreamIO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deepstreamIO/subscriptions","organizations_url":"https://api.github.com/users/deepstreamIO/orgs","repos_url":"https://api.github.com/users/deepstreamIO/repos","events_url":"https://api.github.com/users/deepstreamIO/events{/privacy}","received_events_url":"https://api.github.com/users/deepstreamIO/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/deepstreamIO/deepstream.io-client-js","description":"The Browser / Node.js Client for deepstream.io","fork":false,"url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js","forks_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/forks","keys_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/teams","hooks_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/hooks","issue_events_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/issues/events{/number}","events_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/events","assignees_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/assignees{/user}","branches_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/branches{/branch}","tags_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/tags","blobs_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/statuses/{sha}","languages_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/languages","stargazers_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/stargazers","contributors_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/contributors","subscribers_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/subscribers","subscription_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/subscription","commits_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/contents/{+path}","compare_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/merges","archive_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/downloads","issues_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/issues{/number}","pulls_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/pulls{/number}","milestones_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/milestones{/number}","notifications_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/labels{/name}","releases_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/releases{/id}","deployments_url":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/deployments","created_at":"2014-12-01T06:09:31Z","updated_at":"2016-08-18T18:38:39Z","pushed_at":"2016-08-20T20:54:39Z","git_url":"git://github.com/deepstreamIO/deepstream.io-client-js.git","ssh_url":"git@github.com:deepstreamIO/deepstream.io-client-js.git","clone_url":"https://github.com/deepstreamIO/deepstream.io-client-js.git","svn_url":"https://github.com/deepstreamIO/deepstream.io-client-js","homepage":"","size":1244,"stargazers_count":113,"watchers_count":113,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":24,"mirror_url":null,"open_issues_count":42,"forks":24,"open_issues":42,"watchers":113,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/pulls/214"},"html":{"href":"https://github.com/deepstreamIO/deepstream.io-client-js/pull/214"},"issue":{"href":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/issues/214"},"comments":{"href":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/issues/214/comments"},"review_comments":{"href":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/pulls/214/comments"},"review_comment":{"href":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/pulls/214/commits"},"statuses":{"href":"https://api.github.com/repos/deepstreamIO/deepstream.io-client-js/statuses/345b5576818acf9929b37fdb70b4c206213fcbb0"}}}}
{"actor":{"display_login":"ronag"}}