Commit 30a71566 authored by Victor Loh's avatar Victor Loh Committed by Sara Golemon

Use StringPiece instead of String

Summary:
Using StringPiece makes it easier than std::string

Facebook: Motivation for this diff is found in D1253595

Test Plan:
Added new unittest

fbconfig folly/io/test && fbmake runtests_opt

Reviewed By: simpkins@fb.com

FB internal diff: D1276185
parent 32d518c3
......@@ -98,8 +98,8 @@ class IOBufQueue {
* Copy a string to the end of this queue.
* The caller retains ownership of the source data.
*/
void append(const std::string& buf) {
append(buf.data(), buf.length());
void append(StringPiece sp) {
append(sp.data(), sp.size());
}
/**
......
......@@ -107,6 +107,21 @@ TEST(IOBufQueue, Append2) {
EXPECT_EQ(nullptr, queue2.front());
}
TEST(IOBufQueue, AppendStringPiece) {
std::string s("Hello, World");
IOBufQueue queue(clOptions);
IOBufQueue queue2(clOptions);
queue.append(s.data(), s.length());
queue2.append(s);
checkConsistency(queue);
checkConsistency(queue2);
const IOBuf* chain = queue.front();
const IOBuf* chain2 = queue2.front();
EXPECT_EQ(s.length(), chain->computeChainDataLength());
EXPECT_EQ(s.length(), chain2->computeChainDataLength());
EXPECT_EQ(0, memcmp(chain->data(), chain2->data(), s.length()));
}
TEST(IOBufQueue, Split) {
IOBufQueue queue(clOptions);
queue.append(stringToIOBuf(SCL("Hello")));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment