{"action":"created","comment":{"url":"https://api.github.com/repos/cppformat/cppformat/pulls/comments/45147803","id":45147803,"diff_hunk":"@@ -2628,16 +2639,39 @@ class BasicArrayWriter : public BasicWriter<Char> {\n typedef BasicArrayWriter<char> ArrayWriter;\n typedef BasicArrayWriter<wchar_t> WArrayWriter;\n \n+template<class Elem, class Traits = std::char_traits<Elem> >\n+class basic_formatbuf : public std::basic_streambuf<Elem, Traits> {\n+\n+  typedef typename std::basic_streambuf<Elem, Traits>::int_type int_type;\n+\n+  Buffer<Elem>& buffer_;\n+\n+public:\n+    basic_formatbuf(BasicFormatter<Elem> &formatter) : buffer_(formatter.writer().buffer()) {\n+      setp(buffer_.ptr_, buffer_.ptr_ + buffer_.size_, buffer_.ptr_ + buffer_.capacity_);\n+  }\n+\n+  virtual int_type overflow(int_type _Meta = Traits::eof()) {\n+    buffer_.grow(buffer_.capacity_ * 2);\n+    setp(buffer_.ptr_, buffer_.ptr_ + buffer_.size_, buffer_.ptr_ + buffer_.capacity_);\n+\n+    return traits_type::to_int_type(*pptr());\n+  }\n+\n+  int_type flush() {\n+    buffer_.size_ = pptr() - pbase();\n+    return traits_type::to_int_type(*pptr());\n+  }\n+};\n+\n // Formats a value.\n template <typename Char, typename T>\n-void format(BasicFormatter<Char> &f, const Char *&format_str, const T &value) {\n-  std::basic_ostringstream<Char> os;\n-  os << value;\n-  std::basic_string<Char> str = os.str();\n-  internal::Arg arg = internal::MakeValue<Char>(str);\n-  arg.type = static_cast<internal::Arg::Type>(\n-        internal::MakeValue<Char>::type(str));\n-  format_str = f.format(format_str, arg);","path":"format.h","position":70,"original_position":70,"commit_id":"5343eab4c8dbf7ca33369937bb27940505376f00","original_commit_id":"5343eab4c8dbf7ca33369937bb27940505376f00","user":{"login":"mwinterb","id":1081839,"avatar_url":"https://avatars.githubusercontent.com/u/1081839?v=3","gravatar_id":"","url":"https://api.github.com/users/mwinterb","html_url":"https://github.com/mwinterb","followers_url":"https://api.github.com/users/mwinterb/followers","following_url":"https://api.github.com/users/mwinterb/following{/other_user}","gists_url":"https://api.github.com/users/mwinterb/gists{/gist_id}","starred_url":"https://api.github.com/users/mwinterb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mwinterb/subscriptions","organizations_url":"https://api.github.com/users/mwinterb/orgs","repos_url":"https://api.github.com/users/mwinterb/repos","events_url":"https://api.github.com/users/mwinterb/events{/privacy}","received_events_url":"https://api.github.com/users/mwinterb/received_events","type":"User","site_admin":false},"body":"To be a bit more helpful on my suggestion, keeping the majority of your change the same, except for changing basic_format's constructor to accept a Buffer<Elem> directly:\r\n```c++\r\n// Formats a value.\r\ntemplate <typename Char, typename T>\r\nvoid format(BasicFormatter<Char> &f, const Char *&format_str, const T &value) {\r\n  internal::MemoryBuffer<Char, internal::INLINE_BUFFER_SIZE> buffer;\r\n\r\n  basic_formatbuf<Char> format_buf(buffer);\r\n  std::basic_ostream<Char> output(&format_buf);\r\n  output << value;\r\n  format_buf.flush();\r\n\r\n  BasicStringRef<Char> str(buffer.size() > 0 ? &buffer[0] : NULL, buffer.size());\r\n  internal::Arg arg = internal::MakeValue<Char>(str);\r\n  arg.type = static_cast<internal::Arg::Type>(\r\n        internal::MakeValue<Char>::type(str));\r\n  format_str = f.format(format_str, arg);\r\n}\r\n```\r\nThis passes all of the tests, based on an an older commit, though.","created_at":"2015-11-18T01:18:11Z","updated_at":"2015-11-18T01:18:11Z","html_url":"https://github.com/cppformat/cppformat/pull/230#discussion_r45147803","pull_request_url":"https://api.github.com/repos/cppformat/cppformat/pulls/230","_links":{"self":{"href":"https://api.github.com/repos/cppformat/cppformat/pulls/comments/45147803"},"html":{"href":"https://github.com/cppformat/cppformat/pull/230#discussion_r45147803"},"pull_request":{"href":"https://api.github.com/repos/cppformat/cppformat/pulls/230"}}},"pull_request":{"url":"https://api.github.com/repos/cppformat/cppformat/pulls/230","id":50977630,"html_url":"https://github.com/cppformat/cppformat/pull/230","diff_url":"https://github.com/cppformat/cppformat/pull/230.diff","patch_url":"https://github.com/cppformat/cppformat/pull/230.patch","issue_url":"https://api.github.com/repos/cppformat/cppformat/issues/230","number":230,"state":"open","locked":false,"title":"fmt::format<Char, T> inefficiency #92","user":{"login":"NotImplemented","id":7337332,"avatar_url":"https://avatars.githubusercontent.com/u/7337332?v=3","gravatar_id":"","url":"https://api.github.com/users/NotImplemented","html_url":"https://github.com/NotImplemented","followers_url":"https://api.github.com/users/NotImplemented/followers","following_url":"https://api.github.com/users/NotImplemented/following{/other_user}","gists_url":"https://api.github.com/users/NotImplemented/gists{/gist_id}","starred_url":"https://api.github.com/users/NotImplemented/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NotImplemented/subscriptions","organizations_url":"https://api.github.com/users/NotImplemented/orgs","repos_url":"https://api.github.com/users/NotImplemented/repos","events_url":"https://api.github.com/users/NotImplemented/events{/privacy}","received_events_url":"https://api.github.com/users/NotImplemented/received_events","type":"User","site_admin":false},"body":"Should we write some tests for this item? What is a proper way to run tests locally? ","created_at":"2015-11-17T17:28:14Z","updated_at":"2015-11-18T01:18:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"65da3b30bb8c8a2e393b0027477cc65b545f131f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cppformat/cppformat/pulls/230/commits","review_comments_url":"https://api.github.com/repos/cppformat/cppformat/pulls/230/comments","review_comment_url":"https://api.github.com/repos/cppformat/cppformat/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cppformat/cppformat/issues/230/comments","statuses_url":"https://api.github.com/repos/cppformat/cppformat/statuses/5343eab4c8dbf7ca33369937bb27940505376f00","head":{"label":"NotImplemented:slow-custom-type-format","ref":"slow-custom-type-format","sha":"5343eab4c8dbf7ca33369937bb27940505376f00","user":{"login":"NotImplemented","id":7337332,"avatar_url":"https://avatars.githubusercontent.com/u/7337332?v=3","gravatar_id":"","url":"https://api.github.com/users/NotImplemented","html_url":"https://github.com/NotImplemented","followers_url":"https://api.github.com/users/NotImplemented/followers","following_url":"https://api.github.com/users/NotImplemented/following{/other_user}","gists_url":"https://api.github.com/users/NotImplemented/gists{/gist_id}","starred_url":"https://api.github.com/users/NotImplemented/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NotImplemented/subscriptions","organizations_url":"https://api.github.com/users/NotImplemented/orgs","repos_url":"https://api.github.com/users/NotImplemented/repos","events_url":"https://api.github.com/users/NotImplemented/events{/privacy}","received_events_url":"https://api.github.com/users/NotImplemented/received_events","type":"User","site_admin":false},"repo":{"id":46360184,"name":"cppformat","full_name":"NotImplemented/cppformat","owner":{"login":"NotImplemented","id":7337332,"avatar_url":"https://avatars.githubusercontent.com/u/7337332?v=3","gravatar_id":"","url":"https://api.github.com/users/NotImplemented","html_url":"https://github.com/NotImplemented","followers_url":"https://api.github.com/users/NotImplemented/followers","following_url":"https://api.github.com/users/NotImplemented/following{/other_user}","gists_url":"https://api.github.com/users/NotImplemented/gists{/gist_id}","starred_url":"https://api.github.com/users/NotImplemented/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NotImplemented/subscriptions","organizations_url":"https://api.github.com/users/NotImplemented/orgs","repos_url":"https://api.github.com/users/NotImplemented/repos","events_url":"https://api.github.com/users/NotImplemented/events{/privacy}","received_events_url":"https://api.github.com/users/NotImplemented/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/NotImplemented/cppformat","description":"Small, safe and fast formatting library for C++","fork":true,"url":"https://api.github.com/repos/NotImplemented/cppformat","forks_url":"https://api.github.com/repos/NotImplemented/cppformat/forks","keys_url":"https://api.github.com/repos/NotImplemented/cppformat/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NotImplemented/cppformat/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NotImplemented/cppformat/teams","hooks_url":"https://api.github.com/repos/NotImplemented/cppformat/hooks","issue_events_url":"https://api.github.com/repos/NotImplemented/cppformat/issues/events{/number}","events_url":"https://api.github.com/repos/NotImplemented/cppformat/events","assignees_url":"https://api.github.com/repos/NotImplemented/cppformat/assignees{/user}","branches_url":"https://api.github.com/repos/NotImplemented/cppformat/branches{/branch}","tags_url":"https://api.github.com/repos/NotImplemented/cppformat/tags","blobs_url":"https://api.github.com/repos/NotImplemented/cppformat/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NotImplemented/cppformat/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NotImplemented/cppformat/git/refs{/sha}","trees_url":"https://api.github.com/repos/NotImplemented/cppformat/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NotImplemented/cppformat/statuses/{sha}","languages_url":"https://api.github.com/repos/NotImplemented/cppformat/languages","stargazers_url":"https://api.github.com/repos/NotImplemented/cppformat/stargazers","contributors_url":"https://api.github.com/repos/NotImplemented/cppformat/contributors","subscribers_url":"https://api.github.com/repos/NotImplemented/cppformat/subscribers","subscription_url":"https://api.github.com/repos/NotImplemented/cppformat/subscription","commits_url":"https://api.github.com/repos/NotImplemented/cppformat/commits{/sha}","git_commits_url":"https://api.github.com/repos/NotImplemented/cppformat/git/commits{/sha}","comments_url":"https://api.github.com/repos/NotImplemented/cppformat/comments{/number}","issue_comment_url":"https://api.github.com/repos/NotImplemented/cppformat/issues/comments{/number}","contents_url":"https://api.github.com/repos/NotImplemented/cppformat/contents/{+path}","compare_url":"https://api.github.com/repos/NotImplemented/cppformat/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NotImplemented/cppformat/merges","archive_url":"https://api.github.com/repos/NotImplemented/cppformat/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NotImplemented/cppformat/downloads","issues_url":"https://api.github.com/repos/NotImplemented/cppformat/issues{/number}","pulls_url":"https://api.github.com/repos/NotImplemented/cppformat/pulls{/number}","milestones_url":"https://api.github.com/repos/NotImplemented/cppformat/milestones{/number}","notifications_url":"https://api.github.com/repos/NotImplemented/cppformat/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NotImplemented/cppformat/labels{/name}","releases_url":"https://api.github.com/repos/NotImplemented/cppformat/releases{/id}","created_at":"2015-11-17T16:32:13Z","updated_at":"2015-11-17T16:32:14Z","pushed_at":"2015-11-17T17:24:23Z","git_url":"git://github.com/NotImplemented/cppformat.git","ssh_url":"git@github.com:NotImplemented/cppformat.git","clone_url":"https://github.com/NotImplemented/cppformat.git","svn_url":"https://github.com/NotImplemented/cppformat","homepage":"cppformat.github.io","size":3488,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"cppformat:master","ref":"master","sha":"d9e0f5c04e655a2e0bf3e22f26e534b60078c715","user":{"login":"cppformat","id":7280830,"avatar_url":"https://avatars.githubusercontent.com/u/7280830?v=3","gravatar_id":"","url":"https://api.github.com/users/cppformat","html_url":"https://github.com/cppformat","followers_url":"https://api.github.com/users/cppformat/followers","following_url":"https://api.github.com/users/cppformat/following{/other_user}","gists_url":"https://api.github.com/users/cppformat/gists{/gist_id}","starred_url":"https://api.github.com/users/cppformat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cppformat/subscriptions","organizations_url":"https://api.github.com/users/cppformat/orgs","repos_url":"https://api.github.com/users/cppformat/repos","events_url":"https://api.github.com/users/cppformat/events{/privacy}","received_events_url":"https://api.github.com/users/cppformat/received_events","type":"Organization","site_admin":false},"repo":{"id":7056202,"name":"cppformat","full_name":"cppformat/cppformat","owner":{"login":"cppformat","id":7280830,"avatar_url":"https://avatars.githubusercontent.com/u/7280830?v=3","gravatar_id":"","url":"https://api.github.com/users/cppformat","html_url":"https://github.com/cppformat","followers_url":"https://api.github.com/users/cppformat/followers","following_url":"https://api.github.com/users/cppformat/following{/other_user}","gists_url":"https://api.github.com/users/cppformat/gists{/gist_id}","starred_url":"https://api.github.com/users/cppformat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cppformat/subscriptions","organizations_url":"https://api.github.com/users/cppformat/orgs","repos_url":"https://api.github.com/users/cppformat/repos","events_url":"https://api.github.com/users/cppformat/events{/privacy}","received_events_url":"https://api.github.com/users/cppformat/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cppformat/cppformat","description":"Small, safe and fast formatting library for C++","fork":false,"url":"https://api.github.com/repos/cppformat/cppformat","forks_url":"https://api.github.com/repos/cppformat/cppformat/forks","keys_url":"https://api.github.com/repos/cppformat/cppformat/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cppformat/cppformat/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cppformat/cppformat/teams","hooks_url":"https://api.github.com/repos/cppformat/cppformat/hooks","issue_events_url":"https://api.github.com/repos/cppformat/cppformat/issues/events{/number}","events_url":"https://api.github.com/repos/cppformat/cppformat/events","assignees_url":"https://api.github.com/repos/cppformat/cppformat/assignees{/user}","branches_url":"https://api.github.com/repos/cppformat/cppformat/branches{/branch}","tags_url":"https://api.github.com/repos/cppformat/cppformat/tags","blobs_url":"https://api.github.com/repos/cppformat/cppformat/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cppformat/cppformat/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cppformat/cppformat/git/refs{/sha}","trees_url":"https://api.github.com/repos/cppformat/cppformat/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cppformat/cppformat/statuses/{sha}","languages_url":"https://api.github.com/repos/cppformat/cppformat/languages","stargazers_url":"https://api.github.com/repos/cppformat/cppformat/stargazers","contributors_url":"https://api.github.com/repos/cppformat/cppformat/contributors","subscribers_url":"https://api.github.com/repos/cppformat/cppformat/subscribers","subscription_url":"https://api.github.com/repos/cppformat/cppformat/subscription","commits_url":"https://api.github.com/repos/cppformat/cppformat/commits{/sha}","git_commits_url":"https://api.github.com/repos/cppformat/cppformat/git/commits{/sha}","comments_url":"https://api.github.com/repos/cppformat/cppformat/comments{/number}","issue_comment_url":"https://api.github.com/repos/cppformat/cppformat/issues/comments{/number}","contents_url":"https://api.github.com/repos/cppformat/cppformat/contents/{+path}","compare_url":"https://api.github.com/repos/cppformat/cppformat/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cppformat/cppformat/merges","archive_url":"https://api.github.com/repos/cppformat/cppformat/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cppformat/cppformat/downloads","issues_url":"https://api.github.com/repos/cppformat/cppformat/issues{/number}","pulls_url":"https://api.github.com/repos/cppformat/cppformat/pulls{/number}","milestones_url":"https://api.github.com/repos/cppformat/cppformat/milestones{/number}","notifications_url":"https://api.github.com/repos/cppformat/cppformat/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cppformat/cppformat/labels{/name}","releases_url":"https://api.github.com/repos/cppformat/cppformat/releases{/id}","created_at":"2012-12-07T16:26:46Z","updated_at":"2015-11-17T17:36:54Z","pushed_at":"2015-11-17T17:28:15Z","git_url":"git://github.com/cppformat/cppformat.git","ssh_url":"git@github.com:cppformat/cppformat.git","clone_url":"https://github.com/cppformat/cppformat.git","svn_url":"https://github.com/cppformat/cppformat","homepage":"cppformat.github.io","size":4660,"stargazers_count":1176,"watchers_count":1176,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":139,"mirror_url":null,"open_issues_count":12,"forks":139,"open_issues":12,"watchers":1176,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cppformat/cppformat/pulls/230"},"html":{"href":"https://github.com/cppformat/cppformat/pull/230"},"issue":{"href":"https://api.github.com/repos/cppformat/cppformat/issues/230"},"comments":{"href":"https://api.github.com/repos/cppformat/cppformat/issues/230/comments"},"review_comments":{"href":"https://api.github.com/repos/cppformat/cppformat/pulls/230/comments"},"review_comment":{"href":"https://api.github.com/repos/cppformat/cppformat/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cppformat/cppformat/pulls/230/commits"},"statuses":{"href":"https://api.github.com/repos/cppformat/cppformat/statuses/5343eab4c8dbf7ca33369937bb27940505376f00"}}}}