diff --git a/folly/io/BUCK b/folly/io/BUCK index 2c2ae9c945d..e888da08808 100644 --- a/folly/io/BUCK +++ b/folly/io/BUCK @@ -34,6 +34,7 @@ cpp_library( "//folly:portability", "//folly:range", "//folly:scope_guard", + "//folly/container:span", "//folly/detail:iterators", "//folly/lang:bits", "//folly/lang:checked_math", diff --git a/folly/io/Cursor.h b/folly/io/Cursor.h index 7a0abc9d541..ed52dd17f6b 100644 --- a/folly/io/Cursor.h +++ b/folly/io/Cursor.h @@ -22,13 +22,13 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include #include @@ -678,29 +678,16 @@ class CursorBase { } /** - * Alternate version of peekBytes() that returns a std::basic_string_view + * Alternate version of peekBytes() that returns a std::span * instead of a ByteRage. * * @methodset Accessors */ - std::basic_string_view peekView() { + span peek() { auto bytes = peekBytes(); return {bytes.data(), bytes.size()}; } - /** - * Alternate version of peekBytes() that returns a std::pair - * instead of a ByteRange. - * - * @methodset Accessors - * - * This function will eventually be deprecated. - */ - std::pair peek() { - auto bytes = peekBytes(); - return std::make_pair(bytes.data(), bytes.size()); - } - /** * Clone len bytes from this cursor into an IOBuf. * diff --git a/folly/io/test/IOBufCursorTest.cpp b/folly/io/test/IOBufCursorTest.cpp index 03f9aae0d34..4d302af8afe 100644 --- a/folly/io/test/IOBufCursorTest.cpp +++ b/folly/io/test/IOBufCursorTest.cpp @@ -218,18 +218,18 @@ TEST(IOBuf, PullAndPeek) { { RWPrivateCursor cursor(iobuf1.get()); auto b = cursor.peekBytes(); - EXPECT_EQ(b.data(), cursor.peekView().data()); - EXPECT_EQ(b.size(), cursor.peekView().size()); + EXPECT_EQ(b.data(), cursor.peek().data()); + EXPECT_EQ(b.size(), cursor.peek().size()); EXPECT_EQ("he", StringPiece(b)); cursor.skip(b.size()); b = cursor.peekBytes(); - EXPECT_EQ(b.data(), cursor.peekView().data()); - EXPECT_EQ(b.size(), cursor.peekView().size()); + EXPECT_EQ(b.data(), cursor.peek().data()); + EXPECT_EQ(b.size(), cursor.peek().size()); EXPECT_EQ("llo ", StringPiece(b)); cursor.skip(b.size()); b = cursor.peekBytes(); - EXPECT_EQ(b.data(), cursor.peekView().data()); - EXPECT_EQ(b.size(), cursor.peekView().size()); + EXPECT_EQ(b.data(), cursor.peek().data()); + EXPECT_EQ(b.size(), cursor.peek().size()); EXPECT_EQ("world", StringPiece(b)); cursor.skip(b.size()); EXPECT_EQ(3, iobuf1->countChainElements()); @@ -240,8 +240,8 @@ TEST(IOBuf, PullAndPeek) { RWPrivateCursor cursor(iobuf1.get()); cursor.gather(11); auto b = cursor.peekBytes(); - EXPECT_EQ(b.data(), cursor.peekView().data()); - EXPECT_EQ(b.size(), cursor.peekView().size()); + EXPECT_EQ(b.data(), cursor.peek().data()); + EXPECT_EQ(b.size(), cursor.peek().size()); EXPECT_EQ("hello world", StringPiece(b)); EXPECT_EQ(1, iobuf1->countChainElements()); EXPECT_EQ(11, iobuf1->computeChainDataLength()); @@ -1568,18 +1568,18 @@ TEST(IOBuf, BoundedCursorPullAndPeek) { { Cursor subCursor(iobuf1.get(), 13); auto b = subCursor.peekBytes(); - EXPECT_EQ(b.data(), subCursor.peekView().data()); - EXPECT_EQ(b.size(), subCursor.peekView().size()); + EXPECT_EQ(b.data(), subCursor.peek().data()); + EXPECT_EQ(b.size(), subCursor.peek().size()); EXPECT_EQ("he", StringPiece(b)); subCursor.skip(b.size()); b = subCursor.peekBytes(); - EXPECT_EQ(b.data(), subCursor.peekView().data()); - EXPECT_EQ(b.size(), subCursor.peekView().size()); + EXPECT_EQ(b.data(), subCursor.peek().data()); + EXPECT_EQ(b.size(), subCursor.peek().size()); EXPECT_EQ("llo ", StringPiece(b)); subCursor.skip(b.size()); b = subCursor.peekBytes(); - EXPECT_EQ(b.data(), subCursor.peekView().data()); - EXPECT_EQ(b.size(), subCursor.peekView().size()); + EXPECT_EQ(b.data(), subCursor.peek().data()); + EXPECT_EQ(b.size(), subCursor.peek().size()); EXPECT_EQ("world a", StringPiece(b)); subCursor.skip(b.size()); EXPECT_EQ(3, iobuf1->countChainElements()); diff --git a/folly/somerge_defs.bzl b/folly/somerge_defs.bzl index 7a4dac93142..9eb682e706a 100644 --- a/folly/somerge_defs.bzl +++ b/folly/somerge_defs.bzl @@ -2,7 +2,7 @@ Generated by xplat/cross_plat_devx/somerge_maps/compute_merge_maps.py -@generated SignedSource<<4d6c648a98484ebd6d13a39719f413d2>> +@generated SignedSource<> """ # Entry Points: @@ -132,6 +132,7 @@ FOLLY_BASE_NATIVE_LIBRARY_MERGE_MAP = [ "fbsource//xplat/folly/container:reserveAndroid", "fbsource//xplat/folly/container:small_vectorAndroid", "fbsource//xplat/folly/container:sorted_vector_typesAndroid", + "fbsource//xplat/folly/container:spanAndroid", "fbsource//xplat/folly/container:viewAndroid", "fbsource//xplat/folly/coro:traitsAndroid", "fbsource//xplat/folly/detail:async_traceAndroid",