{"action":"created","comment":{"url":"https://api.github.com/repos/darkgopher/dark/pulls/comments/97656587","pull_request_review_id":18272608,"id":97656587,"diff_hunk":"@@ -0,0 +1,174 @@\n+package dark\n+\n+import (\n+\t\"reflect\"\n+\t\"unsafe\"\n+)\n+\n+// deepCopier keeps track of the pointers we discovered so far.\n+type deepCopier struct {\n+\tpointers map[unsafe.Pointer]interface{}\n+}\n+\n+func (c *deepCopier) deepCopy(i interface{}) interface{} {\n+\tif i == nil {\n+\t\treturn nil\n+\t}\n+\n+\ttyp := reflect.TypeOf(i)\n+\tvalue := reflect.ValueOf(i)\n+\n+\t// if the thing is nil from the start just leave, IsNil only works on\n+\t// certain types though.\n+\tswitch typ.Kind() {\n+\tcase reflect.Chan, reflect.Func, reflect.Interface,\n+\t\treflect.Map, reflect.Ptr, reflect.Slice:\n+\t\tif value.IsNil() {\n+\t\t\treturn value.Interface()\n+\t\t}\n+\t}\n+\n+\tswitch typ.Kind() {\n+\tcase reflect.Bool:\n+\t\treturn value.Bool()\n+\n+\tcase reflect.Int: // ints\n+\t\treturn int(value.Int())\n+\tcase reflect.Int8:\n+\t\treturn int8(value.Int())\n+\tcase reflect.Int16:\n+\t\treturn int16(value.Int())\n+\tcase reflect.Int32:\n+\t\treturn int32(value.Int())\n+\tcase reflect.Int64:\n+\t\treturn int64(value.Int())\n+\n+\tcase reflect.Uint: // uints\n+\t\treturn uint(value.Uint())\n+\tcase reflect.Uint8:\n+\t\treturn uint8(value.Uint())\n+\tcase reflect.Uint16:\n+\t\treturn uint16(value.Uint())\n+\tcase reflect.Uint32:\n+\t\treturn uint32(value.Uint())\n+\tcase reflect.Uint64:\n+\t\treturn uint64(value.Uint())\n+\n+\tcase reflect.Float32: // floats\n+\t\treturn float32(value.Float())\n+\tcase reflect.Float64:\n+\t\treturn float64(value.Float())\n+\n+\tcase reflect.Complex64: // complexs\n+\t\treturn complex64(value.Complex())\n+\tcase reflect.Complex128:\n+\t\treturn complex128(value.Complex())\n+\n+\tcase reflect.Uintptr:\n+\t\treturn value.Pointer()\n+\tcase reflect.UnsafePointer:\n+\t\treturn unsafe.Pointer(value.Pointer())\n+\n+\tcase reflect.String:\n+\t\t// ensure a proper copy of the strings content\n+\t\tsrc := []byte(value.String())\n+\t\treturn string(src)\n+\n+\tcase reflect.Func:\n+\t\t// func cannot be copied per say, that means closures will remain closure.\n+\t\treturn value.Interface()\n+\n+\tcase reflect.Array:\n+\t\ta := reflect.Indirect(reflect.New(typ))\n+\t\tfor i := 0; i < value.Len(); i++ {\n+\t\t\ta.Index(i).Set(reflect.ValueOf(c.deepCopy(value.Index(i).Interface())))\n+\t\t}\n+\t\treturn a.Interface()\n+\tcase reflect.Slice:\n+\t\t// verify if we already have copied that string\n+\t\told, ok := c.pointers[unsafe.Pointer(value.Pointer())]\n+\t\tif ok {\n+\t\t\treturn old\n+\t\t}\n+\n+\t\ts := reflect.MakeSlice(typ, value.Len(), value.Cap())\n+\n+\t\t// store the copy in the map for future references\n+\t\tc.pointers[unsafe.Pointer(value.Pointer())] = s.Interface()\n+\n+\t\tfor i := 0; i < value.Len(); i++ {\n+\t\t\ts.Index(i).Set(reflect.ValueOf(c.deepCopy(value.Index(i).Interface())))\n+\t\t}\n+\n+\t\treturn s.Interface()\n+\n+\tcase reflect.Chan:\n+\t\t// verify if we already have copied that string\n+\t\told, ok := c.pointers[unsafe.Pointer(value.Pointer())]\n+\t\tif ok {\n+\t\t\treturn old\n+\t\t}\n+\n+\t\tch := reflect.MakeChan(typ, value.Len())\n+\n+\t\t// store the copy in the map for future references\n+\t\tc.pointers[unsafe.Pointer(value.Pointer())] = ch.Interface()\n+\n+\t\treturn ch.Interface()\n+\n+\tcase reflect.Map:\n+\t\t// verify if we already have copied that string\n+\t\told, ok := c.pointers[unsafe.Pointer(value.Pointer())]\n+\t\tif ok {\n+\t\t\treturn old\n+\t\t}\n+\n+\t\tm := reflect.MakeMap(typ)\n+\n+\t\t// store the copy in the map for future references\n+\t\tc.pointers[unsafe.Pointer(value.Pointer())] = m.Interface()\n+\n+\t\t// copy the data between maps\n+\t\tfor _, key := range value.MapKeys() {\n+\t\t\tm.SetMapIndex(key, reflect.ValueOf(c.deepCopy(value.MapIndex(key).Interface())))\n+\t\t}\n+\n+\t\treturn m.Interface()\n+\n+\tcase reflect.Struct:\n+\t\ts := reflect.Indirect(reflect.New(typ))\n+\t\tfor i := 0; i < value.NumField(); i++ {\n+\t\t\tSudo(s.Field(i)).Set(reflect.ValueOf(c.deepCopy(Sudo(value.Field(i)).Interface())))\n+\t\t}\n+\t\treturn s.Interface()\n+\tcase reflect.Ptr:\n+\t\t// verify if we already have copied that string\n+\t\tpointto, ok := c.pointers[unsafe.Pointer(value.Pointer())]\n+\t\tif ok {\n+\t\t\treturn pointto\n+\t\t}\n+\n+\t\t// in this case we indirect before allocating so we get a reflect.Value already all set to receive data.\n+\t\tptr := reflect.New(reflect.Indirect(value).Type())\n+\n+\t\tinterf := ptr.Interface()\n+\t\t// store the copy in the map for future references\n+\t\tc.pointers[unsafe.Pointer(value.Pointer())] = interf\n+\n+\t\tcp := reflect.ValueOf(c.deepCopy(reflect.Indirect(value).Interface()))\n+\t\treflect.Indirect(ptr).Set(cp)\n+\n+\t\treturn interf\n+\tcase reflect.Interface:\n+\t\tpanic(\"Is that even reacheable ?\")","path":"deepcopy.go","position":163,"original_position":163,"commit_id":"d20ea862b61b83cf395de3be856628bca83769bd","original_commit_id":"d20ea862b61b83cf395de3be856628bca83769bd","user":{"login":"ScottMansfield","id":184105,"avatar_url":"https://avatars.githubusercontent.com/u/184105?v=3","gravatar_id":"","url":"https://api.github.com/users/ScottMansfield","html_url":"https://github.com/ScottMansfield","followers_url":"https://api.github.com/users/ScottMansfield/followers","following_url":"https://api.github.com/users/ScottMansfield/following{/other_user}","gists_url":"https://api.github.com/users/ScottMansfield/gists{/gist_id}","starred_url":"https://api.github.com/users/ScottMansfield/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ScottMansfield/subscriptions","organizations_url":"https://api.github.com/users/ScottMansfield/orgs","repos_url":"https://api.github.com/users/ScottMansfield/repos","events_url":"https://api.github.com/users/ScottMansfield/events{/privacy}","received_events_url":"https://api.github.com/users/ScottMansfield/received_events","type":"User","site_admin":false},"body":"This ought to be more descriptive so if it does get reached it's not a mystery what triggered it.","created_at":"2017-01-24T21:35:13Z","updated_at":"2017-01-24T21:39:26Z","html_url":"https://github.com/darkgopher/dark/pull/7#discussion_r97656587","pull_request_url":"https://api.github.com/repos/darkgopher/dark/pulls/7","_links":{"self":{"href":"https://api.github.com/repos/darkgopher/dark/pulls/comments/97656587"},"html":{"href":"https://github.com/darkgopher/dark/pull/7#discussion_r97656587"},"pull_request":{"href":"https://api.github.com/repos/darkgopher/dark/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/darkgopher/dark/pulls/7","id":102517632,"html_url":"https://github.com/darkgopher/dark/pull/7","diff_url":"https://github.com/darkgopher/dark/pull/7.diff","patch_url":"https://github.com/darkgopher/dark/pull/7.patch","issue_url":"https://api.github.com/repos/darkgopher/dark/issues/7","number":7,"state":"open","locked":false,"title":"deepcopy","user":{"login":"hydroflame","id":2773127,"avatar_url":"https://avatars.githubusercontent.com/u/2773127?v=3","gravatar_id":"","url":"https://api.github.com/users/hydroflame","html_url":"https://github.com/hydroflame","followers_url":"https://api.github.com/users/hydroflame/followers","following_url":"https://api.github.com/users/hydroflame/following{/other_user}","gists_url":"https://api.github.com/users/hydroflame/gists{/gist_id}","starred_url":"https://api.github.com/users/hydroflame/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hydroflame/subscriptions","organizations_url":"https://api.github.com/users/hydroflame/orgs","repos_url":"https://api.github.com/users/hydroflame/repos","events_url":"https://api.github.com/users/hydroflame/events{/privacy}","received_events_url":"https://api.github.com/users/hydroflame/received_events","type":"User","site_admin":false},"body":"added deep copy","created_at":"2017-01-20T19:04:15Z","updated_at":"2017-01-24T21:39:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"22d09237b3e5f494929b15d0ba15d8f59cdb3dda","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/darkgopher/dark/pulls/7/commits","review_comments_url":"https://api.github.com/repos/darkgopher/dark/pulls/7/comments","review_comment_url":"https://api.github.com/repos/darkgopher/dark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/darkgopher/dark/issues/7/comments","statuses_url":"https://api.github.com/repos/darkgopher/dark/statuses/d20ea862b61b83cf395de3be856628bca83769bd","head":{"label":"darkgopher:deepcopy","ref":"deepcopy","sha":"d20ea862b61b83cf395de3be856628bca83769bd","user":{"login":"darkgopher","id":21111878,"avatar_url":"https://avatars.githubusercontent.com/u/21111878?v=3","gravatar_id":"","url":"https://api.github.com/users/darkgopher","html_url":"https://github.com/darkgopher","followers_url":"https://api.github.com/users/darkgopher/followers","following_url":"https://api.github.com/users/darkgopher/following{/other_user}","gists_url":"https://api.github.com/users/darkgopher/gists{/gist_id}","starred_url":"https://api.github.com/users/darkgopher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/darkgopher/subscriptions","organizations_url":"https://api.github.com/users/darkgopher/orgs","repos_url":"https://api.github.com/users/darkgopher/repos","events_url":"https://api.github.com/users/darkgopher/events{/privacy}","received_events_url":"https://api.github.com/users/darkgopher/received_events","type":"Organization","site_admin":false},"repo":{"id":66033566,"name":"dark","full_name":"darkgopher/dark","owner":{"login":"darkgopher","id":21111878,"avatar_url":"https://avatars.githubusercontent.com/u/21111878?v=3","gravatar_id":"","url":"https://api.github.com/users/darkgopher","html_url":"https://github.com/darkgopher","followers_url":"https://api.github.com/users/darkgopher/followers","following_url":"https://api.github.com/users/darkgopher/following{/other_user}","gists_url":"https://api.github.com/users/darkgopher/gists{/gist_id}","starred_url":"https://api.github.com/users/darkgopher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/darkgopher/subscriptions","organizations_url":"https://api.github.com/users/darkgopher/orgs","repos_url":"https://api.github.com/users/darkgopher/repos","events_url":"https://api.github.com/users/darkgopher/events{/privacy}","received_events_url":"https://api.github.com/users/darkgopher/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/darkgopher/dark","description":"collection of wild use of unsafe/reflect","fork":false,"url":"https://api.github.com/repos/darkgopher/dark","forks_url":"https://api.github.com/repos/darkgopher/dark/forks","keys_url":"https://api.github.com/repos/darkgopher/dark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/darkgopher/dark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/darkgopher/dark/teams","hooks_url":"https://api.github.com/repos/darkgopher/dark/hooks","issue_events_url":"https://api.github.com/repos/darkgopher/dark/issues/events{/number}","events_url":"https://api.github.com/repos/darkgopher/dark/events","assignees_url":"https://api.github.com/repos/darkgopher/dark/assignees{/user}","branches_url":"https://api.github.com/repos/darkgopher/dark/branches{/branch}","tags_url":"https://api.github.com/repos/darkgopher/dark/tags","blobs_url":"https://api.github.com/repos/darkgopher/dark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/darkgopher/dark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/darkgopher/dark/git/refs{/sha}","trees_url":"https://api.github.com/repos/darkgopher/dark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/darkgopher/dark/statuses/{sha}","languages_url":"https://api.github.com/repos/darkgopher/dark/languages","stargazers_url":"https://api.github.com/repos/darkgopher/dark/stargazers","contributors_url":"https://api.github.com/repos/darkgopher/dark/contributors","subscribers_url":"https://api.github.com/repos/darkgopher/dark/subscribers","subscription_url":"https://api.github.com/repos/darkgopher/dark/subscription","commits_url":"https://api.github.com/repos/darkgopher/dark/commits{/sha}","git_commits_url":"https://api.github.com/repos/darkgopher/dark/git/commits{/sha}","comments_url":"https://api.github.com/repos/darkgopher/dark/comments{/number}","issue_comment_url":"https://api.github.com/repos/darkgopher/dark/issues/comments{/number}","contents_url":"https://api.github.com/repos/darkgopher/dark/contents/{+path}","compare_url":"https://api.github.com/repos/darkgopher/dark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/darkgopher/dark/merges","archive_url":"https://api.github.com/repos/darkgopher/dark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/darkgopher/dark/downloads","issues_url":"https://api.github.com/repos/darkgopher/dark/issues{/number}","pulls_url":"https://api.github.com/repos/darkgopher/dark/pulls{/number}","milestones_url":"https://api.github.com/repos/darkgopher/dark/milestones{/number}","notifications_url":"https://api.github.com/repos/darkgopher/dark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/darkgopher/dark/labels{/name}","releases_url":"https://api.github.com/repos/darkgopher/dark/releases{/id}","deployments_url":"https://api.github.com/repos/darkgopher/dark/deployments","created_at":"2016-08-18T22:03:29Z","updated_at":"2017-01-05T07:36:35Z","pushed_at":"2017-01-20T19:44:38Z","git_url":"git://github.com/darkgopher/dark.git","ssh_url":"git@github.com:darkgopher/dark.git","clone_url":"https://github.com/darkgopher/dark.git","svn_url":"https://github.com/darkgopher/dark","homepage":"","size":23,"stargazers_count":15,"watchers_count":15,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":15,"default_branch":"master"}},"base":{"label":"darkgopher:master","ref":"master","sha":"b28258bb18e19a51ae4490f7d32dbc85e27feb3c","user":{"login":"darkgopher","id":21111878,"avatar_url":"https://avatars.githubusercontent.com/u/21111878?v=3","gravatar_id":"","url":"https://api.github.com/users/darkgopher","html_url":"https://github.com/darkgopher","followers_url":"https://api.github.com/users/darkgopher/followers","following_url":"https://api.github.com/users/darkgopher/following{/other_user}","gists_url":"https://api.github.com/users/darkgopher/gists{/gist_id}","starred_url":"https://api.github.com/users/darkgopher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/darkgopher/subscriptions","organizations_url":"https://api.github.com/users/darkgopher/orgs","repos_url":"https://api.github.com/users/darkgopher/repos","events_url":"https://api.github.com/users/darkgopher/events{/privacy}","received_events_url":"https://api.github.com/users/darkgopher/received_events","type":"Organization","site_admin":false},"repo":{"id":66033566,"name":"dark","full_name":"darkgopher/dark","owner":{"login":"darkgopher","id":21111878,"avatar_url":"https://avatars.githubusercontent.com/u/21111878?v=3","gravatar_id":"","url":"https://api.github.com/users/darkgopher","html_url":"https://github.com/darkgopher","followers_url":"https://api.github.com/users/darkgopher/followers","following_url":"https://api.github.com/users/darkgopher/following{/other_user}","gists_url":"https://api.github.com/users/darkgopher/gists{/gist_id}","starred_url":"https://api.github.com/users/darkgopher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/darkgopher/subscriptions","organizations_url":"https://api.github.com/users/darkgopher/orgs","repos_url":"https://api.github.com/users/darkgopher/repos","events_url":"https://api.github.com/users/darkgopher/events{/privacy}","received_events_url":"https://api.github.com/users/darkgopher/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/darkgopher/dark","description":"collection of wild use of unsafe/reflect","fork":false,"url":"https://api.github.com/repos/darkgopher/dark","forks_url":"https://api.github.com/repos/darkgopher/dark/forks","keys_url":"https://api.github.com/repos/darkgopher/dark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/darkgopher/dark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/darkgopher/dark/teams","hooks_url":"https://api.github.com/repos/darkgopher/dark/hooks","issue_events_url":"https://api.github.com/repos/darkgopher/dark/issues/events{/number}","events_url":"https://api.github.com/repos/darkgopher/dark/events","assignees_url":"https://api.github.com/repos/darkgopher/dark/assignees{/user}","branches_url":"https://api.github.com/repos/darkgopher/dark/branches{/branch}","tags_url":"https://api.github.com/repos/darkgopher/dark/tags","blobs_url":"https://api.github.com/repos/darkgopher/dark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/darkgopher/dark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/darkgopher/dark/git/refs{/sha}","trees_url":"https://api.github.com/repos/darkgopher/dark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/darkgopher/dark/statuses/{sha}","languages_url":"https://api.github.com/repos/darkgopher/dark/languages","stargazers_url":"https://api.github.com/repos/darkgopher/dark/stargazers","contributors_url":"https://api.github.com/repos/darkgopher/dark/contributors","subscribers_url":"https://api.github.com/repos/darkgopher/dark/subscribers","subscription_url":"https://api.github.com/repos/darkgopher/dark/subscription","commits_url":"https://api.github.com/repos/darkgopher/dark/commits{/sha}","git_commits_url":"https://api.github.com/repos/darkgopher/dark/git/commits{/sha}","comments_url":"https://api.github.com/repos/darkgopher/dark/comments{/number}","issue_comment_url":"https://api.github.com/repos/darkgopher/dark/issues/comments{/number}","contents_url":"https://api.github.com/repos/darkgopher/dark/contents/{+path}","compare_url":"https://api.github.com/repos/darkgopher/dark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/darkgopher/dark/merges","archive_url":"https://api.github.com/repos/darkgopher/dark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/darkgopher/dark/downloads","issues_url":"https://api.github.com/repos/darkgopher/dark/issues{/number}","pulls_url":"https://api.github.com/repos/darkgopher/dark/pulls{/number}","milestones_url":"https://api.github.com/repos/darkgopher/dark/milestones{/number}","notifications_url":"https://api.github.com/repos/darkgopher/dark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/darkgopher/dark/labels{/name}","releases_url":"https://api.github.com/repos/darkgopher/dark/releases{/id}","deployments_url":"https://api.github.com/repos/darkgopher/dark/deployments","created_at":"2016-08-18T22:03:29Z","updated_at":"2017-01-05T07:36:35Z","pushed_at":"2017-01-20T19:44:38Z","git_url":"git://github.com/darkgopher/dark.git","ssh_url":"git@github.com:darkgopher/dark.git","clone_url":"https://github.com/darkgopher/dark.git","svn_url":"https://github.com/darkgopher/dark","homepage":"","size":23,"stargazers_count":15,"watchers_count":15,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":15,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/darkgopher/dark/pulls/7"},"html":{"href":"https://github.com/darkgopher/dark/pull/7"},"issue":{"href":"https://api.github.com/repos/darkgopher/dark/issues/7"},"comments":{"href":"https://api.github.com/repos/darkgopher/dark/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/darkgopher/dark/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/darkgopher/dark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/darkgopher/dark/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/darkgopher/dark/statuses/d20ea862b61b83cf395de3be856628bca83769bd"}}}}
{"actor":{"display_login":"ScottMansfield"}}