{"action":"created","issue":{"url":"https://api.github.com/repos/scodec/scodec-bits/issues/48","repository_url":"https://api.github.com/repos/scodec/scodec-bits","labels_url":"https://api.github.com/repos/scodec/scodec-bits/issues/48/labels{/name}","comments_url":"https://api.github.com/repos/scodec/scodec-bits/issues/48/comments","events_url":"https://api.github.com/repos/scodec/scodec-bits/issues/48/events","html_url":"https://github.com/scodec/scodec-bits/issues/48","id":155162716,"number":48,"title":"Add filter to ByteVector","user":{"login":"searler","id":220239,"avatar_url":"https://avatars.githubusercontent.com/u/220239?v=3","gravatar_id":"","url":"https://api.github.com/users/searler","html_url":"https://github.com/searler","followers_url":"https://api.github.com/users/searler/followers","following_url":"https://api.github.com/users/searler/following{/other_user}","gists_url":"https://api.github.com/users/searler/gists{/gist_id}","starred_url":"https://api.github.com/users/searler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/searler/subscriptions","organizations_url":"https://api.github.com/users/searler/orgs","repos_url":"https://api.github.com/users/searler/repos","events_url":"https://api.github.com/users/searler/events{/privacy}","received_events_url":"https://api.github.com/users/searler/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-05-17T02:18:08Z","updated_at":"2016-12-21T00:52:31Z","closed_at":null,"body":"I have a need to remove escape characters from a ByteVector. This is easy enough to implement, but has  poor performance. \n\nMy use case is a custom \"wireshark\" that uses the pcap functionality to capture and display the operation of a networked API. The de-escape code is ~75% of the total runtime!\n\nMy first attempt was modeled on the algorithms seen within the scodec codebase.\n\n```\nprivate val escape = hex\"10\"\n\nprivate def unescaped(bytes: ByteVector): ByteVector = unescaped(bytes,ByteVector.empty)\n\n  @tailrec private def unescaped(bytes: ByteVector, accum:ByteVector): ByteVector = {\n    bytes indexOfSlice (escape) match {\n      case -1 => accum ++ bytes\n      case idx =>\n           unescaped(bytes.drop(idx + 2), accum ++ bytes.take(idx) ++ bytes.slice(idx + 1, idx + 2))\n    }\n  }\n```\n\nThe following is much simpler and about 25% faster (although less general)\n\n```\nByteVector(bytes.toSeq.filterNot { _ == 0x10 })\n```\n\nThe next step would be to build a set of micro-benchmarks and test a variety of algorithms.\n\nPresumably a variant of the map() code is needed to efficiently implement filter\n"},"comment":{"url":"https://api.github.com/repos/scodec/scodec-bits/issues/comments/268403213","html_url":"https://github.com/scodec/scodec-bits/issues/48#issuecomment-268403213","issue_url":"https://api.github.com/repos/scodec/scodec-bits/issues/48","id":268403213,"user":{"login":"mpilquist","id":118078,"avatar_url":"https://avatars.githubusercontent.com/u/118078?v=3","gravatar_id":"","url":"https://api.github.com/users/mpilquist","html_url":"https://github.com/mpilquist","followers_url":"https://api.github.com/users/mpilquist/followers","following_url":"https://api.github.com/users/mpilquist/following{/other_user}","gists_url":"https://api.github.com/users/mpilquist/gists{/gist_id}","starred_url":"https://api.github.com/users/mpilquist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpilquist/subscriptions","organizations_url":"https://api.github.com/users/mpilquist/orgs","repos_url":"https://api.github.com/users/mpilquist/repos","events_url":"https://api.github.com/users/mpilquist/events{/privacy}","received_events_url":"https://api.github.com/users/mpilquist/received_events","type":"User","site_admin":false},"created_at":"2016-12-21T00:52:31Z","updated_at":"2016-12-21T00:52:31Z","body":"@searler Are you still in need of an efficient `filter`?"}}
{"actor":{"display_login":"mpilquist"}}