Remove usage of base::make_span(): base/
Replace with span() CTAD use, or more targeted helpers.
Also removes some unnecessary uses of base::.
Bug: 341907909
Change-Id: I521bbcd1bc6aa622be75093fc82a02543cb31dc7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6052443
Auto-Submit: Peter Kasting <[email protected]>
Reviewed-by: Tom Sepez <[email protected]>
Commit-Queue: Peter Kasting <[email protected]>
Code-Coverage: [email protected] <[email protected]>
Commit-Queue: Tom Sepez <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1388924}
diff --git a/base/allocator/miracle_parameter.h b/base/allocator/miracle_parameter.h
index 68716789..7a5d23b 100644
--- a/base/allocator/miracle_parameter.h
+++ b/base/allocator/miracle_parameter.h
@@ -166,7 +166,7 @@
default_value, type, options) \
type function_name() { \
static const type value = miracle_parameter::GetMiracleParameterAsEnum( \
- feature, param_name, default_value, base::make_span(options)); \
+ feature, param_name, default_value, base::span(options)); \
return value; \
}
diff --git a/base/allocator/partition_alloc_support.cc b/base/allocator/partition_alloc_support.cc
index 442fcb0..878a9f5c 100644
--- a/base/allocator/partition_alloc_support.cc
+++ b/base/allocator/partition_alloc_support.cc
@@ -674,9 +674,9 @@
LOG(ERROR) << debug::StackTrace(
// This call truncates the `nullptr` tail of the stack
// trace (see the `is_partitioned` CHECK above).
- make_span(raw_stack_trace.begin(),
- ranges::partition_point(
- raw_stack_trace, is_frame_ptr_not_null)))
+ span(raw_stack_trace.begin(),
+ ranges::partition_point(raw_stack_trace,
+ is_frame_ptr_not_null)))
<< "\n";
}
#else
diff --git a/base/apple/foundation_util.h b/base/apple/foundation_util.h
index 66c092f..44a7b73 100644
--- a/base/apple/foundation_util.h
+++ b/base/apple/foundation_util.h
@@ -308,7 +308,7 @@
inline span<const uint8_t> NSDataToSpan(NSData* data) {
// SAFETY: `NSData` guarantees that `bytes` is exactly `length` in size.
return UNSAFE_BUFFERS(
- make_span(static_cast<const uint8_t*>(data.bytes), data.length));
+ span(static_cast<const uint8_t*>(data.bytes), size_t{data.length}));
}
// Returns a mutable `base::span<uint8_t>` pointing to the memory owned by
@@ -320,7 +320,7 @@
// SAFETY: `NSMutableData` guarantees that `mutableBytes` is exactly `length`
// in size.
return UNSAFE_BUFFERS(
- make_span(static_cast<uint8_t*>(data.mutableBytes), data.length));
+ span(static_cast<uint8_t*>(data.mutableBytes), size_t{data.length}));
}
#endif // defined(__OBJC__)
diff --git a/base/apple/foundation_util_unittest.mm b/base/apple/foundation_util_unittest.mm
index 55ffec30..08ea54e 100644
--- a/base/apple/foundation_util_unittest.mm
+++ b/base/apple/foundation_util_unittest.mm
@@ -521,17 +521,17 @@
{
ScopedCFTypeRef<CFDataRef> data(
CFDataCreate(nullptr, buffer, sizeof(buffer)));
- span<const uint8_t> span = CFDataToSpan(data.get());
- EXPECT_EQ(make_span(buffer), span);
- EXPECT_THAT(span, ElementsAreArray(buffer));
+ span<const uint8_t> data_span = CFDataToSpan(data.get());
+ EXPECT_EQ(span(buffer), data_span);
+ EXPECT_THAT(data_span, ElementsAreArray(buffer));
}
{
ScopedCFTypeRef<CFMutableDataRef> data(CFDataCreateMutable(nullptr, 0));
CFDataAppendBytes(data.get(), buffer, sizeof(buffer));
- span<uint8_t> span = CFMutableDataToSpan(data.get());
- EXPECT_EQ(make_span(buffer), span);
- span[0] = 123;
+ span<uint8_t> data_span = CFMutableDataToSpan(data.get());
+ EXPECT_EQ(span(buffer), data_span);
+ data_span[0] = 123;
EXPECT_EQ(CFDataGetBytePtr(data.get())[0], 123);
}
}
diff --git a/base/base64_unittest.cc b/base/base64_unittest.cc
index 948bf622..bff8eee 100644
--- a/base/base64_unittest.cc
+++ b/base/base64_unittest.cc
@@ -144,7 +144,7 @@
// crash. This test is only meaningful because `EXPECT_CHECK_DEATH` looks for
// a `CHECK`-based failure.
uint8_t b;
- auto large_span = base::make_span(&b, MODP_B64_MAX_INPUT_LEN + 1);
+ auto large_span = span(&b, MODP_B64_MAX_INPUT_LEN + 1);
EXPECT_CHECK_DEATH(Base64Encode(large_span));
std::string output = "PREFIX";
diff --git a/base/containers/adapters_unittest.cc b/base/containers/adapters_unittest.cc
index 6c3f334c..483fd75 100644
--- a/base/containers/adapters_unittest.cc
+++ b/base/containers/adapters_unittest.cc
@@ -72,12 +72,12 @@
static_assert(std::ranges::sized_range<decltype(base::Reversed(s))>);
static_assert(std::ranges::borrowed_range<decltype(base::Reversed(s))>);
- auto make_span = [] { return base::span<int>(); };
- static_assert(std::ranges::range<decltype(base::Reversed(make_span()))>);
+ auto rvalue_span = [] { return base::span<int>(); };
+ static_assert(std::ranges::range<decltype(base::Reversed(rvalue_span()))>);
static_assert(
- std::ranges::sized_range<decltype(base::Reversed(make_span()))>);
+ std::ranges::sized_range<decltype(base::Reversed(rvalue_span()))>);
static_assert(
- std::ranges::borrowed_range<decltype(base::Reversed(make_span()))>);
+ std::ranges::borrowed_range<decltype(base::Reversed(rvalue_span()))>);
}
{
diff --git a/base/containers/span_nocompile.nc b/base/containers/span_nocompile.nc
index 11ccb608..fffa95f 100644
--- a/base/containers/span_nocompile.nc
+++ b/base/containers/span_nocompile.nc
@@ -136,12 +136,12 @@
// as_writable_bytes should not be possible for a const container.
void AsWritableBytesWithConstContainerDisallowed() {
const std::vector<int> v = {1, 2, 3};
- span<uint8_t> bytes = as_writable_bytes(make_span(v)); // expected-error {{no matching function for call to 'as_writable_bytes'}}
+ span<uint8_t> bytes = as_writable_bytes(span(v)); // expected-error {{no matching function for call to 'as_writable_bytes'}}
}
void ConstVectorDeducesAsConstSpan() {
const std::vector<int> v;
- span<int> s = make_span(v); // expected-error-re@*:* {{no viable conversion from 'span<{{.*}}, [...]>' to 'span<int, [...]>'}}
+ span<int> s = span(v); // expected-error-re@*:* {{no viable conversion from 'span<{{.*}}, [...]>' to 'span<int, [...]>'}}
}
// A span can only be constructed from a range rvalue when the element type is
diff --git a/base/containers/span_unittest.cc b/base/containers/span_unittest.cc
index eff4e8e..896b198 100644
--- a/base/containers/span_unittest.cc
+++ b/base/containers/span_unittest.cc
@@ -1637,7 +1637,7 @@
TEST(SpanTest, AsBytes) {
{
constexpr int kArray[] = {2, 3, 5, 7, 11, 13};
- auto bytes_span = as_bytes(make_span(kArray));
+ auto bytes_span = as_bytes(span(kArray));
static_assert(std::is_same_v<decltype(bytes_span),
span<const uint8_t, sizeof(kArray)>>);
EXPECT_EQ(reinterpret_cast<const uint8_t*>(kArray), bytes_span.data());
@@ -1691,7 +1691,7 @@
TEST(SpanTest, AsChars) {
{
constexpr int kArray[] = {2, 3, 5, 7, 11, 13};
- auto chars_span = as_chars(make_span(kArray));
+ auto chars_span = as_chars(span(kArray));
static_assert(
std::is_same_v<decltype(chars_span), span<const char, sizeof(kArray)>>);
EXPECT_EQ(reinterpret_cast<const char*>(kArray), chars_span.data());
@@ -2187,11 +2187,11 @@
TEST(SpanTest, CopyFrom) {
int arr[] = {1, 2, 3};
span<int, 0> empty_static_span;
- span<int, 3> static_span = make_span(arr);
+ span<int, 3> static_span = span(arr);
std::vector<int> vec = {4, 5, 6};
span<int> empty_dynamic_span;
- span<int> dynamic_span = make_span(vec);
+ span<int> dynamic_span = span(vec);
// Handle empty cases gracefully.
// Dynamic size to static size requires an explicit conversion.
@@ -2321,11 +2321,11 @@
TEST(SpanTest, CopyFromNonoverlapping) {
int arr[] = {1, 2, 3};
span<int, 0> empty_static_span;
- span<int, 3> static_span = make_span(arr);
+ span<int, 3> static_span = span(arr);
std::vector<int> vec = {4, 5, 6};
span<int> empty_dynamic_span;
- span<int> dynamic_span = make_span(vec);
+ span<int> dynamic_span = span(vec);
// Handle empty cases gracefully.
UNSAFE_BUFFERS({
@@ -2366,10 +2366,10 @@
TEST(SpanTest, CopyFromConversion) {
int arr[] = {1, 2, 3};
- span<int, 3> static_span = make_span(arr);
+ span<int, 3> static_span = span(arr);
std::vector<int> vec = {4, 5, 6};
- span<int> dynamic_span = make_span(vec);
+ span<int> dynamic_span = span(vec);
std::vector convert_from = {7, 8, 9};
static_span.copy_from(convert_from);
@@ -2457,11 +2457,11 @@
TEST(SpanTest, SplitAt) {
int arr[] = {1, 2, 3};
span<int, 0> empty_static_span;
- span<int, 3> static_span = make_span(arr);
+ span<int, 3> static_span = span(arr);
std::vector<int> vec = {4, 5, 6};
span<int> empty_dynamic_span;
- span<int> dynamic_span = make_span(vec);
+ span<int> dynamic_span = span(vec);
{
auto [left, right] = empty_static_span.split_at(0u);
diff --git a/base/files/file_unittest.cc b/base/files/file_unittest.cc
index d5f7e0c5..057f0d5 100644
--- a/base/files/file_unittest.cc
+++ b/base/files/file_unittest.cc
@@ -35,11 +35,10 @@
#include "base/test/gtest_util.h"
#endif
-using base::File;
-using base::FilePath;
+namespace base {
TEST(FileTest, Create) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("create_file_1");
@@ -47,35 +46,35 @@
// Don't create a File at all.
File file;
EXPECT_FALSE(file.IsValid());
- EXPECT_EQ(base::File::FILE_ERROR_FAILED, file.error_details());
+ EXPECT_EQ(File::FILE_ERROR_FAILED, file.error_details());
- File file2(base::File::FILE_ERROR_TOO_MANY_OPENED);
+ File file2(File::FILE_ERROR_TOO_MANY_OPENED);
EXPECT_FALSE(file2.IsValid());
- EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, file2.error_details());
+ EXPECT_EQ(File::FILE_ERROR_TOO_MANY_OPENED, file2.error_details());
}
{
// Open a file that doesn't exist.
- File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ);
+ File file(file_path, File::FLAG_OPEN | File::FLAG_READ);
EXPECT_FALSE(file.IsValid());
- EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, file.error_details());
- EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, base::File::GetLastFileError());
+ EXPECT_EQ(File::FILE_ERROR_NOT_FOUND, file.error_details());
+ EXPECT_EQ(File::FILE_ERROR_NOT_FOUND, File::GetLastFileError());
}
{
// Open or create a file.
- File file(file_path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ);
+ File file(file_path, File::FLAG_OPEN_ALWAYS | File::FLAG_READ);
EXPECT_TRUE(file.IsValid());
EXPECT_TRUE(file.created());
- EXPECT_EQ(base::File::FILE_OK, file.error_details());
+ EXPECT_EQ(File::FILE_OK, file.error_details());
}
{
// Open an existing file.
- File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ);
+ File file(file_path, File::FLAG_OPEN | File::FLAG_READ);
EXPECT_TRUE(file.IsValid());
EXPECT_FALSE(file.created());
- EXPECT_EQ(base::File::FILE_OK, file.error_details());
+ EXPECT_EQ(File::FILE_OK, file.error_details());
// This time verify closing the file.
file.Close();
@@ -85,10 +84,10 @@
{
// Open an existing file through Initialize
File file;
- file.Initialize(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ);
+ file.Initialize(file_path, File::FLAG_OPEN | File::FLAG_READ);
EXPECT_TRUE(file.IsValid());
EXPECT_FALSE(file.created());
- EXPECT_EQ(base::File::FILE_OK, file.error_details());
+ EXPECT_EQ(File::FILE_OK, file.error_details());
// This time verify closing the file.
file.Close();
@@ -97,97 +96,91 @@
{
// Create a file that exists.
- File file(file_path, base::File::FLAG_CREATE | base::File::FLAG_READ);
+ File file(file_path, File::FLAG_CREATE | File::FLAG_READ);
EXPECT_FALSE(file.IsValid());
EXPECT_FALSE(file.created());
- EXPECT_EQ(base::File::FILE_ERROR_EXISTS, file.error_details());
- EXPECT_EQ(base::File::FILE_ERROR_EXISTS, base::File::GetLastFileError());
+ EXPECT_EQ(File::FILE_ERROR_EXISTS, file.error_details());
+ EXPECT_EQ(File::FILE_ERROR_EXISTS, File::GetLastFileError());
}
{
// Create or overwrite a file.
- File file(file_path,
- base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
+ File file(file_path, File::FLAG_CREATE_ALWAYS | File::FLAG_WRITE);
EXPECT_TRUE(file.IsValid());
EXPECT_TRUE(file.created());
- EXPECT_EQ(base::File::FILE_OK, file.error_details());
+ EXPECT_EQ(File::FILE_OK, file.error_details());
}
{
// Create a delete-on-close file.
file_path = temp_dir.GetPath().AppendASCII("create_file_2");
- File file(file_path,
- base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ |
- base::File::FLAG_DELETE_ON_CLOSE);
+ File file(file_path, File::FLAG_OPEN_ALWAYS | File::FLAG_READ |
+ File::FLAG_DELETE_ON_CLOSE);
EXPECT_TRUE(file.IsValid());
EXPECT_TRUE(file.created());
- EXPECT_EQ(base::File::FILE_OK, file.error_details());
+ EXPECT_EQ(File::FILE_OK, file.error_details());
}
- EXPECT_FALSE(base::PathExists(file_path));
+ EXPECT_FALSE(PathExists(file_path));
}
TEST(FileTest, SelfSwap) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("create_file_1");
- File file(file_path,
- base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_DELETE_ON_CLOSE);
+ File file(file_path, File::FLAG_OPEN_ALWAYS | File::FLAG_DELETE_ON_CLOSE);
std::swap(file, file);
EXPECT_TRUE(file.IsValid());
}
TEST(FileTest, Async) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("create_file");
{
- File file(file_path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_ASYNC);
+ File file(file_path, File::FLAG_OPEN_ALWAYS | File::FLAG_ASYNC);
EXPECT_TRUE(file.IsValid());
EXPECT_TRUE(file.async());
}
{
- File file(file_path, base::File::FLAG_OPEN_ALWAYS);
+ File file(file_path, File::FLAG_OPEN_ALWAYS);
EXPECT_TRUE(file.IsValid());
EXPECT_FALSE(file.async());
}
}
TEST(FileTest, DeleteOpenFile) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("create_file_1");
// Create a file.
- File file(file_path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ |
- base::File::FLAG_WIN_SHARE_DELETE);
+ File file(file_path, File::FLAG_OPEN_ALWAYS | File::FLAG_READ |
+ File::FLAG_WIN_SHARE_DELETE);
EXPECT_TRUE(file.IsValid());
EXPECT_TRUE(file.created());
- EXPECT_EQ(base::File::FILE_OK, file.error_details());
+ EXPECT_EQ(File::FILE_OK, file.error_details());
// Open an existing file and mark it as delete on close.
- File same_file(file_path,
- base::File::FLAG_OPEN | base::File::FLAG_DELETE_ON_CLOSE |
- base::File::FLAG_READ);
+ File same_file(file_path, File::FLAG_OPEN | File::FLAG_DELETE_ON_CLOSE |
+ File::FLAG_READ);
EXPECT_TRUE(file.IsValid());
EXPECT_FALSE(same_file.created());
- EXPECT_EQ(base::File::FILE_OK, same_file.error_details());
+ EXPECT_EQ(File::FILE_OK, same_file.error_details());
// Close both handles and check that the file is gone.
file.Close();
same_file.Close();
- EXPECT_FALSE(base::PathExists(file_path));
+ EXPECT_FALSE(PathExists(file_path));
}
TEST(FileTest, ReadWrite) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("read_write_file");
- File file(file_path,
- base::File::FLAG_CREATE | base::File::FLAG_READ |
- base::File::FLAG_WRITE);
+ File file(file_path, File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE);
ASSERT_TRUE(file.IsValid());
char data_to_write[] = "test";
@@ -214,8 +207,9 @@
const int kPartialReadOffset = 1;
bytes_read = file.Read(kPartialReadOffset, data_read_1, kTestDataSize);
EXPECT_EQ(kTestDataSize - kPartialReadOffset, bytes_read);
- for (int i = 0; i < bytes_read; i++)
+ for (int i = 0; i < bytes_read; i++) {
EXPECT_EQ(data_to_write[i + kPartialReadOffset], data_read_1[i]);
+ }
// Read 0 bytes.
bytes_read = file.Read(0, data_read_1, 0);
@@ -224,12 +218,13 @@
// Read the entire file.
bytes_read = file.Read(0, data_read_1, kTestDataSize);
EXPECT_EQ(kTestDataSize, bytes_read);
- for (int i = 0; i < bytes_read; i++)
+ for (int i = 0; i < bytes_read; i++) {
EXPECT_EQ(data_to_write[i], data_read_1[i]);
+ }
// Read again, but using the trivial native wrapper.
std::optional<size_t> maybe_bytes_read =
- file.ReadNoBestEffort(0, base::as_writable_byte_span(data_read_1)
+ file.ReadNoBestEffort(0, as_writable_byte_span(data_read_1)
.first(static_cast<size_t>(kTestDataSize)));
ASSERT_TRUE(maybe_bytes_read.has_value());
EXPECT_LE(maybe_bytes_read.value(), static_cast<size_t>(kTestDataSize));
@@ -240,8 +235,8 @@
// Write past the end of the file.
const int kOffsetBeyondEndOfFile = 10;
const int kPartialWriteLength = 2;
- bytes_written = file.Write(kOffsetBeyondEndOfFile,
- data_to_write, kPartialWriteLength);
+ bytes_written =
+ file.Write(kOffsetBeyondEndOfFile, data_to_write, kPartialWriteLength);
EXPECT_EQ(kPartialWriteLength, bytes_written);
// Make sure the file was extended.
@@ -253,30 +248,32 @@
char data_read_2[32];
bytes_read = file.Read(0, data_read_2, static_cast<int>(file_size.value()));
EXPECT_EQ(file_size, bytes_read);
- for (int i = 0; i < kTestDataSize; i++)
+ for (int i = 0; i < kTestDataSize; i++) {
EXPECT_EQ(data_to_write[i], data_read_2[i]);
- for (int i = kTestDataSize; i < kOffsetBeyondEndOfFile; i++)
+ }
+ for (int i = kTestDataSize; i < kOffsetBeyondEndOfFile; i++) {
EXPECT_EQ(0, data_read_2[i]);
- for (int i = kOffsetBeyondEndOfFile; i < file_size; i++)
+ }
+ for (int i = kOffsetBeyondEndOfFile; i < file_size; i++) {
EXPECT_EQ(data_to_write[i - kOffsetBeyondEndOfFile], data_read_2[i]);
+ }
}
TEST(FileTest, ReadWriteSpans) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("read_write_file");
- File file(file_path, base::File::FLAG_CREATE | base::File::FLAG_READ |
- base::File::FLAG_WRITE);
+ File file(file_path, File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE);
ASSERT_TRUE(file.IsValid());
// Write 0 bytes to the file.
- std::optional<size_t> bytes_written = file.Write(0, base::span<uint8_t>());
+ std::optional<size_t> bytes_written = file.Write(0, span<uint8_t>());
ASSERT_TRUE(bytes_written.has_value());
EXPECT_EQ(0u, bytes_written.value());
// Write "test" to the file.
std::string data_to_write("test");
- bytes_written = file.Write(0, base::as_byte_span(data_to_write));
+ bytes_written = file.Write(0, as_byte_span(data_to_write));
ASSERT_TRUE(bytes_written.has_value());
EXPECT_EQ(data_to_write.size(), bytes_written.value());
@@ -297,7 +294,7 @@
}
// Read 0 bytes.
- bytes_read = file.Read(0, base::span<uint8_t>());
+ bytes_read = file.Read(0, span<uint8_t>());
ASSERT_TRUE(bytes_read.has_value());
EXPECT_EQ(0u, bytes_read.value());
@@ -314,7 +311,7 @@
const size_t kPartialWriteLength = 2;
bytes_written =
file.Write(kOffsetBeyondEndOfFile,
- base::as_byte_span(data_to_write).first(kPartialWriteLength));
+ as_byte_span(data_to_write).first(kPartialWriteLength));
ASSERT_TRUE(bytes_written.has_value());
EXPECT_EQ(kPartialWriteLength, bytes_written.value());
@@ -348,7 +345,7 @@
#endif
EXPECT_EQ(File::FILE_ERROR_ACCESS_DENIED, File::GetLastFileError());
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath nonexistent_path(temp_dir.GetPath().AppendASCII("nonexistent"));
@@ -360,10 +357,10 @@
}
TEST(FileTest, Append) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("append_file");
- File file(file_path, base::File::FLAG_CREATE | base::File::FLAG_APPEND);
+ File file(file_path, File::FLAG_CREATE | File::FLAG_APPEND);
ASSERT_TRUE(file.IsValid());
char data_to_write[] = "test";
@@ -382,9 +379,7 @@
EXPECT_EQ(kTestDataSize, bytes_written);
file.Close();
- File file2(file_path,
- base::File::FLAG_OPEN | base::File::FLAG_READ |
- base::File::FLAG_APPEND);
+ File file2(file_path, File::FLAG_OPEN | File::FLAG_READ | File::FLAG_APPEND);
ASSERT_TRUE(file2.IsValid());
// Test passing the file around.
@@ -401,23 +396,21 @@
// Read the entire file.
char data_read_1[32];
- int bytes_read = file.Read(0, data_read_1,
- kTestDataSize + kAppendDataSize);
+ int bytes_read = file.Read(0, data_read_1, kTestDataSize + kAppendDataSize);
EXPECT_EQ(kTestDataSize + kAppendDataSize, bytes_read);
- for (int i = 0; i < kTestDataSize; i++)
+ for (int i = 0; i < kTestDataSize; i++) {
EXPECT_EQ(data_to_write[i], data_read_1[i]);
- for (int i = 0; i < kAppendDataSize; i++)
+ }
+ for (int i = 0; i < kAppendDataSize; i++) {
EXPECT_EQ(append_data_to_write[i], data_read_1[kTestDataSize + i]);
+ }
}
-
TEST(FileTest, Length) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("truncate_file");
- File file(file_path,
- base::File::FLAG_CREATE | base::File::FLAG_READ |
- base::File::FLAG_WRITE);
+ File file(file_path, File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE);
ASSERT_TRUE(file.IsValid());
EXPECT_EQ(0, file.GetLength());
@@ -439,10 +432,12 @@
char data_read[32];
int bytes_read = file.Read(0, data_read, static_cast<int>(file_size.value()));
EXPECT_EQ(file_size, bytes_read);
- for (int i = 0; i < kTestDataSize; i++)
+ for (int i = 0; i < kTestDataSize; i++) {
EXPECT_EQ(data_to_write[i], data_read[i]);
- for (int i = kTestDataSize; i < file_size; i++)
+ }
+ for (int i = kTestDataSize; i < file_size; i++) {
EXPECT_EQ(0, data_read[i]);
+ }
// Truncate the file.
const int kTruncatedFileLength = 2;
@@ -470,11 +465,10 @@
EXPECT_EQ(kBigFileLength, file_size.value());
#endif
- // Close the file and reopen with base::File::FLAG_CREATE_ALWAYS, and make
+ // Close the file and reopen with File::FLAG_CREATE_ALWAYS, and make
// sure the file is empty (old file was overridden).
file.Close();
- file.Initialize(file_path,
- base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
+ file.Initialize(file_path, File::FLAG_CREATE_ALWAYS | File::FLAG_WRITE);
EXPECT_EQ(0, file.GetLength());
}
@@ -484,27 +478,26 @@
#else
TEST(FileTest, DISABLED_TouchGetInfo) {
#endif
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
File file(temp_dir.GetPath().AppendASCII("touch_get_info_file"),
- base::File::FLAG_CREATE | base::File::FLAG_WRITE |
- base::File::FLAG_WRITE_ATTRIBUTES);
+ File::FLAG_CREATE | File::FLAG_WRITE | File::FLAG_WRITE_ATTRIBUTES);
ASSERT_TRUE(file.IsValid());
// Get info for a newly created file.
- base::File::Info info;
+ File::Info info;
EXPECT_TRUE(file.GetInfo(&info));
// Add 2 seconds to account for possible rounding errors on
// filesystems that use a 1s or 2s timestamp granularity.
- base::Time now = base::Time::Now() + base::Seconds(2);
+ Time now = Time::Now() + Seconds(2);
EXPECT_EQ(0, info.size);
EXPECT_FALSE(info.is_directory);
EXPECT_FALSE(info.is_symbolic_link);
EXPECT_LE(info.last_accessed.ToInternalValue(), now.ToInternalValue());
EXPECT_LE(info.last_modified.ToInternalValue(), now.ToInternalValue());
EXPECT_LE(info.creation_time.ToInternalValue(), now.ToInternalValue());
- base::Time creation_time = info.creation_time;
+ Time creation_time = info.creation_time;
// Write "test" to the file.
char data[] = "test";
@@ -516,8 +509,8 @@
// It's best to add values that are multiples of 2 (in seconds)
// to the current last_accessed and last_modified times, because
// FATxx uses a 2s timestamp granularity.
- base::Time new_last_accessed = info.last_accessed + base::Seconds(234);
- base::Time new_last_modified = info.last_modified + base::Minutes(567);
+ Time new_last_accessed = info.last_accessed + Seconds(234);
+ Time new_last_modified = info.last_modified + Minutes(567);
EXPECT_TRUE(file.SetTimes(new_last_accessed, new_last_modified));
@@ -547,19 +540,18 @@
// Test we can retrieve the file's creation time through File::GetInfo().
TEST(FileTest, GetInfoForCreationTime) {
int64_t before_creation_time_s =
- base::Time::Now().ToDeltaSinceWindowsEpoch().InSeconds();
+ Time::Now().ToDeltaSinceWindowsEpoch().InSeconds();
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("test_file");
- File file(file_path, base::File::FLAG_CREATE | base::File::FLAG_READ |
- base::File::FLAG_WRITE);
+ File file(file_path, File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE);
EXPECT_TRUE(file.IsValid());
int64_t after_creation_time_s =
- base::Time::Now().ToDeltaSinceWindowsEpoch().InSeconds();
+ Time::Now().ToDeltaSinceWindowsEpoch().InSeconds();
- base::File::Info info;
+ File::Info info;
EXPECT_TRUE(file.GetInfo(&info));
EXPECT_GE(info.creation_time.ToDeltaSinceWindowsEpoch().InSeconds(),
before_creation_time_s);
@@ -568,20 +560,18 @@
}
TEST(FileTest, ReadAtCurrentPosition) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path =
temp_dir.GetPath().AppendASCII("read_at_current_position");
- File file(file_path,
- base::File::FLAG_CREATE | base::File::FLAG_READ |
- base::File::FLAG_WRITE);
+ File file(file_path, File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE);
EXPECT_TRUE(file.IsValid());
const char kData[] = "test";
const int kDataSize = sizeof(kData) - 1;
EXPECT_EQ(kDataSize, file.Write(0, kData, kDataSize));
- EXPECT_EQ(0, file.Seek(base::File::FROM_BEGIN, 0));
+ EXPECT_EQ(0, file.Seek(File::FROM_BEGIN, 0));
char buffer[kDataSize];
int first_chunk_size = kDataSize / 2;
@@ -593,45 +583,36 @@
}
TEST(FileTest, ReadAtCurrentPositionSpans) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path =
temp_dir.GetPath().AppendASCII("read_at_current_position");
- File file(file_path, base::File::FLAG_CREATE | base::File::FLAG_READ |
- base::File::FLAG_WRITE);
+ File file(file_path, File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE);
EXPECT_TRUE(file.IsValid());
std::string data("test");
- std::optional<size_t> result = file.Write(0, base::as_byte_span(data));
+ std::optional<size_t> result = file.Write(0, as_byte_span(data));
ASSERT_TRUE(result.has_value());
EXPECT_EQ(data.size(), result.value());
- EXPECT_EQ(0, file.Seek(base::File::FROM_BEGIN, 0));
+ EXPECT_EQ(0, file.Seek(File::FROM_BEGIN, 0));
uint8_t buffer[4];
size_t first_chunk_size = 2;
- result =
- file.ReadAtCurrentPos(base::make_span(buffer).first(first_chunk_size));
- ASSERT_TRUE(result.has_value());
- EXPECT_EQ(first_chunk_size, result.value());
-
- result =
- file.ReadAtCurrentPos(base::make_span(buffer).subspan(first_chunk_size));
- ASSERT_TRUE(result.has_value());
- EXPECT_EQ(first_chunk_size, result.value());
+ const auto [chunk1, chunk2] = span(buffer).split_at(first_chunk_size);
+ EXPECT_EQ(chunk1.size(), file.ReadAtCurrentPos(chunk1));
+ EXPECT_EQ(chunk2.size(), file.ReadAtCurrentPos(chunk2));
for (size_t i = 0; i < data.size(); i++) {
EXPECT_EQ(data[i], static_cast<char>(buffer[i]));
}
}
TEST(FileTest, WriteAtCurrentPosition) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path =
temp_dir.GetPath().AppendASCII("write_at_current_position");
- File file(file_path,
- base::File::FLAG_CREATE | base::File::FLAG_READ |
- base::File::FLAG_WRITE);
+ File file(file_path, File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE);
EXPECT_TRUE(file.IsValid());
const char kData[] = "test";
@@ -649,23 +630,21 @@
}
TEST(FileTest, WriteAtCurrentPositionSpans) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path =
temp_dir.GetPath().AppendASCII("write_at_current_position");
- File file(file_path, base::File::FLAG_CREATE | base::File::FLAG_READ |
- base::File::FLAG_WRITE);
+ File file(file_path, File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE);
EXPECT_TRUE(file.IsValid());
std::string data("test");
size_t first_chunk_size = data.size() / 2;
std::optional<size_t> result =
- file.WriteAtCurrentPos(base::as_byte_span(data).first(first_chunk_size));
+ file.WriteAtCurrentPos(as_byte_span(data).first(first_chunk_size));
ASSERT_TRUE(result.has_value());
EXPECT_EQ(first_chunk_size, result.value());
- result = file.WriteAtCurrentPos(
- base::as_byte_span(data).subspan(first_chunk_size));
+ result = file.WriteAtCurrentPos(as_byte_span(data).subspan(first_chunk_size));
ASSERT_TRUE(result.has_value());
EXPECT_EQ(first_chunk_size, result.value());
@@ -676,29 +655,26 @@
}
TEST(FileTest, Seek) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("seek_file");
- File file(file_path,
- base::File::FLAG_CREATE | base::File::FLAG_READ |
- base::File::FLAG_WRITE);
+ File file(file_path, File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE);
ASSERT_TRUE(file.IsValid());
const int64_t kOffset = 10;
- EXPECT_EQ(kOffset, file.Seek(base::File::FROM_BEGIN, kOffset));
- EXPECT_EQ(2 * kOffset, file.Seek(base::File::FROM_CURRENT, kOffset));
- EXPECT_EQ(kOffset, file.Seek(base::File::FROM_CURRENT, -kOffset));
+ EXPECT_EQ(kOffset, file.Seek(File::FROM_BEGIN, kOffset));
+ EXPECT_EQ(2 * kOffset, file.Seek(File::FROM_CURRENT, kOffset));
+ EXPECT_EQ(kOffset, file.Seek(File::FROM_CURRENT, -kOffset));
EXPECT_TRUE(file.SetLength(kOffset * 2));
- EXPECT_EQ(kOffset, file.Seek(base::File::FROM_END, -kOffset));
+ EXPECT_EQ(kOffset, file.Seek(File::FROM_END, -kOffset));
}
TEST(FileTest, Duplicate) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("file");
- File file(file_path,(base::File::FLAG_CREATE |
- base::File::FLAG_READ |
- base::File::FLAG_WRITE));
+ File file(file_path,
+ (File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE));
ASSERT_TRUE(file.IsValid());
File file2(file.Duplicate());
@@ -708,11 +684,11 @@
static const char kData[] = "now is a good time.";
static const int kDataLen = sizeof(kData) - 1;
- ASSERT_EQ(0, file.Seek(base::File::FROM_CURRENT, 0));
- ASSERT_EQ(0, file2.Seek(base::File::FROM_CURRENT, 0));
+ ASSERT_EQ(0, file.Seek(File::FROM_CURRENT, 0));
+ ASSERT_EQ(0, file2.Seek(File::FROM_CURRENT, 0));
ASSERT_EQ(kDataLen, file.WriteAtCurrentPos(kData, kDataLen));
- ASSERT_EQ(kDataLen, file.Seek(base::File::FROM_CURRENT, 0));
- ASSERT_EQ(kDataLen, file2.Seek(base::File::FROM_CURRENT, 0));
+ ASSERT_EQ(kDataLen, file.Seek(File::FROM_CURRENT, 0));
+ ASSERT_EQ(kDataLen, file2.Seek(File::FROM_CURRENT, 0));
file.Close();
char buf[kDataLen];
ASSERT_EQ(kDataLen, file2.Read(0, &buf[0], kDataLen));
@@ -720,30 +696,27 @@
}
TEST(FileTest, DuplicateDeleteOnClose) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("file");
- File file(file_path,(base::File::FLAG_CREATE |
- base::File::FLAG_READ |
- base::File::FLAG_WRITE |
- base::File::FLAG_DELETE_ON_CLOSE));
+ File file(file_path, (File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE |
+ File::FLAG_DELETE_ON_CLOSE));
ASSERT_TRUE(file.IsValid());
File file2(file.Duplicate());
ASSERT_TRUE(file2.IsValid());
file.Close();
file2.Close();
- ASSERT_FALSE(base::PathExists(file_path));
+ ASSERT_FALSE(PathExists(file_path));
}
#if BUILDFLAG(ENABLE_BASE_TRACING)
TEST(FileTest, TracedValueSupport) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("file");
- File file(file_path,
- (base::File::FLAG_CREATE | base::File::FLAG_READ |
- base::File::FLAG_WRITE | base::File::FLAG_DELETE_ON_CLOSE));
+ File file(file_path, (File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE |
+ File::FLAG_DELETE_ON_CLOSE));
ASSERT_TRUE(file.IsValid());
EXPECT_EQ(perfetto::TracedValueToString(file),
@@ -758,12 +731,11 @@
#define MAYBE_WriteDataToLargeOffset WriteDataToLargeOffset
#endif
TEST(FileTest, MAYBE_WriteDataToLargeOffset) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("file");
- File file(file_path,
- (base::File::FLAG_CREATE | base::File::FLAG_READ |
- base::File::FLAG_WRITE | base::File::FLAG_DELETE_ON_CLOSE));
+ File file(file_path, (File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE |
+ File::FLAG_DELETE_ON_CLOSE));
ASSERT_TRUE(file.IsValid());
const char kData[] = "this file is sparse.";
@@ -772,35 +744,36 @@
// If the file fails to write, it is probably we are running out of disk space
// and the file system doesn't support sparse file.
- if (file.Write(kLargeFileOffset - kDataLen - 1, kData, kDataLen) < 0)
+ if (file.Write(kLargeFileOffset - kDataLen - 1, kData, kDataLen) < 0) {
return;
+ }
ASSERT_EQ(kDataLen, file.Write(kLargeFileOffset + 1, kData, kDataLen));
}
TEST(FileTest, AddFlagsForPassingToUntrustedProcess) {
{
- uint32_t flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
- flags = base::File::AddFlagsForPassingToUntrustedProcess(flags);
- EXPECT_EQ(flags, base::File::FLAG_OPEN | base::File::FLAG_READ);
+ uint32_t flags = File::FLAG_OPEN | File::FLAG_READ;
+ flags = File::AddFlagsForPassingToUntrustedProcess(flags);
+ EXPECT_EQ(flags, File::FLAG_OPEN | File::FLAG_READ);
}
{
- uint32_t flags = base::File::FLAG_OPEN | base::File::FLAG_WRITE;
- flags = base::File::AddFlagsForPassingToUntrustedProcess(flags);
- EXPECT_EQ(flags, base::File::FLAG_OPEN | base::File::FLAG_WRITE |
- base::File::FLAG_WIN_NO_EXECUTE);
+ uint32_t flags = File::FLAG_OPEN | File::FLAG_WRITE;
+ flags = File::AddFlagsForPassingToUntrustedProcess(flags);
+ EXPECT_EQ(flags,
+ File::FLAG_OPEN | File::FLAG_WRITE | File::FLAG_WIN_NO_EXECUTE);
}
}
#if BUILDFLAG(IS_WIN)
TEST(FileTest, GetInfoForDirectory) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath empty_dir =
temp_dir.GetPath().Append(FILE_PATH_LITERAL("gpfi_test"));
ASSERT_TRUE(CreateDirectory(empty_dir));
- base::File dir(
+ File dir(
::CreateFile(empty_dir.value().c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
OPEN_EXISTING,
@@ -808,7 +781,7 @@
NULL));
ASSERT_TRUE(dir.IsValid());
- base::File::Info info;
+ File::Info info;
EXPECT_TRUE(dir.GetInfo(&info));
EXPECT_TRUE(info.is_directory);
EXPECT_FALSE(info.is_symbolic_link);
@@ -816,63 +789,59 @@
}
TEST(FileTest, DeleteNoop) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("file");
// Creating and closing a file with DELETE perms should do nothing special.
- File file(file_path,
- (base::File::FLAG_CREATE | base::File::FLAG_READ |
- base::File::FLAG_WRITE | base::File::FLAG_CAN_DELETE_ON_CLOSE));
+ File file(file_path, (File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE |
+ File::FLAG_CAN_DELETE_ON_CLOSE));
ASSERT_TRUE(file.IsValid());
file.Close();
- ASSERT_TRUE(base::PathExists(file_path));
+ ASSERT_TRUE(PathExists(file_path));
}
TEST(FileTest, Delete) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("file");
// Creating a file with DELETE and then marking for delete on close should
// delete it.
- File file(file_path,
- (base::File::FLAG_CREATE | base::File::FLAG_READ |
- base::File::FLAG_WRITE | base::File::FLAG_CAN_DELETE_ON_CLOSE));
+ File file(file_path, (File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE |
+ File::FLAG_CAN_DELETE_ON_CLOSE));
ASSERT_TRUE(file.IsValid());
ASSERT_TRUE(file.DeleteOnClose(true));
file.Close();
- ASSERT_FALSE(base::PathExists(file_path));
+ ASSERT_FALSE(PathExists(file_path));
}
TEST(FileTest, DeleteThenRevoke) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("file");
// Creating a file with DELETE, marking it for delete, then clearing delete on
// close should not delete it.
- File file(file_path,
- (base::File::FLAG_CREATE | base::File::FLAG_READ |
- base::File::FLAG_WRITE | base::File::FLAG_CAN_DELETE_ON_CLOSE));
+ File file(file_path, (File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE |
+ File::FLAG_CAN_DELETE_ON_CLOSE));
ASSERT_TRUE(file.IsValid());
ASSERT_TRUE(file.DeleteOnClose(true));
ASSERT_TRUE(file.DeleteOnClose(false));
file.Close();
- ASSERT_TRUE(base::PathExists(file_path));
+ ASSERT_TRUE(PathExists(file_path));
}
TEST(FileTest, IrrevokableDeleteOnClose) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("file");
// DELETE_ON_CLOSE cannot be revoked by this opener.
File file(file_path,
- (base::File::FLAG_CREATE | base::File::FLAG_READ |
- base::File::FLAG_WRITE | base::File::FLAG_DELETE_ON_CLOSE |
- base::File::FLAG_WIN_SHARE_DELETE |
- base::File::FLAG_CAN_DELETE_ON_CLOSE));
+ (File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE |
+ File::FLAG_DELETE_ON_CLOSE | File::FLAG_WIN_SHARE_DELETE |
+ File::FLAG_CAN_DELETE_ON_CLOSE));
ASSERT_TRUE(file.IsValid());
// https://msdn.microsoft.com/library/windows/desktop/aa364221.aspx says that
// setting the dispositon has no effect if the handle was opened with
@@ -881,84 +850,80 @@
// to indicate success on Windows 10.)
file.DeleteOnClose(false);
file.Close();
- ASSERT_FALSE(base::PathExists(file_path));
+ ASSERT_FALSE(PathExists(file_path));
}
TEST(FileTest, IrrevokableDeleteOnCloseOther) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("file");
// DELETE_ON_CLOSE cannot be revoked by another opener.
File file(file_path,
- (base::File::FLAG_CREATE | base::File::FLAG_READ |
- base::File::FLAG_WRITE | base::File::FLAG_DELETE_ON_CLOSE |
- base::File::FLAG_WIN_SHARE_DELETE |
- base::File::FLAG_CAN_DELETE_ON_CLOSE));
+ (File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE |
+ File::FLAG_DELETE_ON_CLOSE | File::FLAG_WIN_SHARE_DELETE |
+ File::FLAG_CAN_DELETE_ON_CLOSE));
ASSERT_TRUE(file.IsValid());
File file2(file_path,
- (base::File::FLAG_OPEN | base::File::FLAG_READ |
- base::File::FLAG_WRITE | base::File::FLAG_WIN_SHARE_DELETE |
- base::File::FLAG_CAN_DELETE_ON_CLOSE));
+ (File::FLAG_OPEN | File::FLAG_READ | File::FLAG_WRITE |
+ File::FLAG_WIN_SHARE_DELETE | File::FLAG_CAN_DELETE_ON_CLOSE));
ASSERT_TRUE(file2.IsValid());
file2.DeleteOnClose(false);
file2.Close();
- ASSERT_TRUE(base::PathExists(file_path));
+ ASSERT_TRUE(PathExists(file_path));
file.Close();
- ASSERT_FALSE(base::PathExists(file_path));
+ ASSERT_FALSE(PathExists(file_path));
}
TEST(FileTest, DeleteWithoutPermission) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("file");
// It should not be possible to mark a file for deletion when it was not
// created/opened with DELETE.
- File file(file_path, (base::File::FLAG_CREATE | base::File::FLAG_READ |
- base::File::FLAG_WRITE));
+ File file(file_path,
+ (File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE));
ASSERT_TRUE(file.IsValid());
ASSERT_FALSE(file.DeleteOnClose(true));
file.Close();
- ASSERT_TRUE(base::PathExists(file_path));
+ ASSERT_TRUE(PathExists(file_path));
}
TEST(FileTest, UnsharedDeleteOnClose) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("file");
// Opening with DELETE_ON_CLOSE when a previous opener hasn't enabled sharing
// will fail.
- File file(file_path, (base::File::FLAG_CREATE | base::File::FLAG_READ |
- base::File::FLAG_WRITE));
+ File file(file_path,
+ (File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE));
ASSERT_TRUE(file.IsValid());
- File file2(
- file_path,
- (base::File::FLAG_OPEN | base::File::FLAG_READ | base::File::FLAG_WRITE |
- base::File::FLAG_DELETE_ON_CLOSE | base::File::FLAG_WIN_SHARE_DELETE));
+ File file2(file_path,
+ (File::FLAG_OPEN | File::FLAG_READ | File::FLAG_WRITE |
+ File::FLAG_DELETE_ON_CLOSE | File::FLAG_WIN_SHARE_DELETE));
ASSERT_FALSE(file2.IsValid());
file.Close();
- ASSERT_TRUE(base::PathExists(file_path));
+ ASSERT_TRUE(PathExists(file_path));
}
TEST(FileTest, NoDeleteOnCloseWithMappedFile) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("file");
// Mapping a file into memory blocks DeleteOnClose.
- File file(file_path,
- (base::File::FLAG_CREATE | base::File::FLAG_READ |
- base::File::FLAG_WRITE | base::File::FLAG_CAN_DELETE_ON_CLOSE));
+ File file(file_path, (File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE |
+ File::FLAG_CAN_DELETE_ON_CLOSE));
ASSERT_TRUE(file.IsValid());
ASSERT_EQ(5, file.WriteAtCurrentPos("12345", 5));
{
- base::MemoryMappedFile mapping;
+ MemoryMappedFile mapping;
ASSERT_TRUE(mapping.Initialize(file.Duplicate()));
ASSERT_EQ(5U, mapping.length());
@@ -966,17 +931,16 @@
}
file.Close();
- ASSERT_TRUE(base::PathExists(file_path));
+ ASSERT_TRUE(PathExists(file_path));
}
// Check that we handle the async bit being set incorrectly in a sane way.
TEST(FileTest, UseSyncApiWithAsyncFile) {
- base::ScopedTempDir temp_dir;
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath file_path = temp_dir.GetPath().AppendASCII("file");
- File file(file_path, base::File::FLAG_CREATE | base::File::FLAG_WRITE |
- base::File::FLAG_ASYNC);
+ File file(file_path, File::FLAG_CREATE | File::FLAG_WRITE | File::FLAG_ASYNC);
File lying_file(file.TakePlatformFile(), false /* async */);
ASSERT_TRUE(lying_file.IsValid());
@@ -989,7 +953,7 @@
// When this test is running as Admin, TMP gets ignored and temporary
// files/folders are created in %ProgramFiles%. This means that the
// temporary folder created by the death test never gets deleted, as it
- // crashes before the `base::ScopedTempDir` goes out of scope and also
+ // crashes before the `ScopedTempDir` goes out of scope and also
// does not get automatically cleaned by by the test runner.
//
// To avoid this from happening, this death test explicitly creates the
@@ -997,16 +961,17 @@
// process to a temporary folder for the test. This means that the
// folder created here is always deleted during test runner cleanup.
std::string tmp_folder;
- ASSERT_TRUE(base::Environment::Create()->GetVar("TMP", &tmp_folder));
- base::ScopedTempDir temp_dir;
+ ASSERT_TRUE(Environment::Create()->GetVar("TMP", &tmp_folder));
+ ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDirUnderPath(
- base::FilePath(base::UTF8ToWide(tmp_folder))));
+ FilePath(UTF8ToWide(tmp_folder))));
FilePath file_path = temp_dir.GetPath().AppendASCII("file");
- File file(file_path,
- base::File::FLAG_CREATE | base::File::FLAG_WIN_EXECUTE |
- base::File::FLAG_READ | base::File::FLAG_WIN_NO_EXECUTE);
+ File file(file_path, File::FLAG_CREATE | File::FLAG_WIN_EXECUTE |
+ File::FLAG_READ | File::FLAG_WIN_NO_EXECUTE);
},
"FLAG_WIN_NO_EXECUTE");
}
#endif // BUILDFLAG(IS_WIN)
+
+} // namespace base
diff --git a/base/files/file_util.cc b/base/files/file_util.cc
index f85fda2..6211201 100644
--- a/base/files/file_util.cc
+++ b/base/files/file_util.cc
@@ -331,7 +331,7 @@
bool read_successs = ReadStreamToSpanWithMaxSize(
stream, max_size, [&content_string](size_t size) {
content_string.resize(size);
- return as_writable_bytes(make_span(content_string));
+ return as_writable_byte_span(content_string);
});
if (contents) {
@@ -355,7 +355,7 @@
std::numeric_limits<size_t>::max(),
[&bytes](size_t size) {
bytes.resize(size);
- return make_span(bytes);
+ return span(bytes);
})) {
return std::nullopt;
}
@@ -486,7 +486,7 @@
return -1;
}
std::optional<uint64_t> result =
- ReadFile(filename, make_span(data, static_cast<uint32_t>(max_size)));
+ ReadFile(filename, span(data, static_cast<uint32_t>(max_size)));
if (!result) {
return -1;
}
@@ -494,7 +494,7 @@
}
bool WriteFile(const FilePath& filename, std::string_view data) {
- return WriteFile(filename, as_bytes(make_span(data)));
+ return WriteFile(filename, as_byte_span(data));
}
FilePath GetUniquePath(const FilePath& path) {
diff --git a/base/files/file_util_posix.cc b/base/files/file_util_posix.cc
index 25b37054..c1f484b 100644
--- a/base/files/file_util_posix.cc
+++ b/base/files/file_util_posix.cc
@@ -1101,7 +1101,7 @@
}
bool WriteFileDescriptor(int fd, std::string_view data) {
- return WriteFileDescriptor(fd, as_bytes(make_span(data)));
+ return WriteFileDescriptor(fd, as_byte_span(data));
}
bool AllocateFileRegion(File* file, int64_t offset, size_t size) {
@@ -1210,7 +1210,7 @@
}
bool AppendToFile(const FilePath& filename, std::string_view data) {
- return AppendToFile(filename, as_bytes(make_span(data)));
+ return AppendToFile(filename, as_byte_span(data));
}
bool GetCurrentDirectory(FilePath* dir) {
diff --git a/base/files/file_util_win.cc b/base/files/file_util_win.cc
index ec523fd40..f93a90c 100644
--- a/base/files/file_util_win.cc
+++ b/base/files/file_util_win.cc
@@ -1034,7 +1034,7 @@
}
bool AppendToFile(const FilePath& filename, std::string_view data) {
- return AppendToFile(filename, as_bytes(make_span(data)));
+ return AppendToFile(filename, as_byte_span(data));
}
bool GetCurrentDirectory(FilePath* dir) {
diff --git a/base/hash/hash.cc b/base/hash/hash.cc
index 6c75a3f..9a23491 100644
--- a/base/hash/hash.cc
+++ b/base/hash/hash.cc
@@ -148,7 +148,7 @@
}
uint32_t PersistentHash(std::string_view str) {
- return PersistentHash(as_bytes(make_span(str)));
+ return PersistentHash(as_byte_span(str));
}
size_t HashInts32(uint32_t value1, uint32_t value2) {
diff --git a/base/hash/hash.h b/base/hash/hash.h
index 335bc3d7..3464d61e 100644
--- a/base/hash/hash.h
+++ b/base/hash/hash.h
@@ -35,7 +35,7 @@
// May changed without warning, do not expect stability of outputs.
BASE_EXPORT size_t FastHash(base::span<const uint8_t> data);
inline size_t FastHash(std::string_view str) {
- return FastHash(as_bytes(make_span(str)));
+ return FastHash(as_byte_span(str));
}
// Computes a hash of a memory buffer. This hash function must not change so
diff --git a/base/hash/legacy_hash_unittest.cc b/base/hash/legacy_hash_unittest.cc
index 8b6d76f..353a6c4 100644
--- a/base/hash/legacy_hash_unittest.cc
+++ b/base/hash/legacy_hash_unittest.cc
@@ -26,13 +26,12 @@
};
for (const auto& test_case : kTestCases) {
SCOPED_TRACE(test_case.input);
- auto bytes = as_bytes(make_span(test_case.input));
- EXPECT_EQ(test_case.output, CityHash64(bytes));
+ EXPECT_EQ(test_case.output, CityHash64(as_byte_span(test_case.input)));
}
for (const auto& test_case : kTestCases) {
SCOPED_TRACE(test_case.input);
- auto bytes = as_bytes(make_span(test_case.input));
- EXPECT_EQ(test_case.output_with_seed, CityHash64WithSeed(bytes, 112358));
+ EXPECT_EQ(test_case.output_with_seed,
+ CityHash64WithSeed(as_byte_span(test_case.input), 112358));
}
}
diff --git a/base/i18n/streaming_utf8_validator_unittest.cc b/base/i18n/streaming_utf8_validator_unittest.cc
index 0398b02..a6dafec 100644
--- a/base/i18n/streaming_utf8_validator_unittest.cc
+++ b/base/i18n/streaming_utf8_validator_unittest.cc
@@ -282,28 +282,24 @@
// test.
TEST(StreamingUtf8ValidatorTest, NulIsValid) {
static const char kNul[] = "\x00";
- EXPECT_EQ(VALID_ENDPOINT, StreamingUtf8Validator().AddBytes(
- base::as_bytes(base::make_span(kNul, 1u))));
+ EXPECT_EQ(VALID_ENDPOINT,
+ StreamingUtf8Validator().AddBytes(byte_span_from_cstring(kNul)));
}
// Just a basic sanity test before we start getting fancy.
TEST(StreamingUtf8ValidatorTest, HelloWorld) {
static const char kHelloWorld[] = "Hello, World!";
- EXPECT_EQ(VALID_ENDPOINT,
- StreamingUtf8Validator().AddBytes(base::as_bytes(
- base::make_span(kHelloWorld, strlen(kHelloWorld)))));
+ EXPECT_EQ(VALID_ENDPOINT, StreamingUtf8Validator().AddBytes(
+ byte_span_from_cstring(kHelloWorld)));
}
// Check that the Reset() method works.
TEST(StreamingUtf8ValidatorTest, ResetWorks) {
StreamingUtf8Validator validator;
- EXPECT_EQ(INVALID,
- validator.AddBytes(base::as_bytes(base::make_span("\xC0", 1u))));
- EXPECT_EQ(INVALID,
- validator.AddBytes(base::as_bytes(base::make_span("a", 1u))));
+ EXPECT_EQ(INVALID, validator.AddBytes(byte_span_from_cstring("\xC0")));
+ EXPECT_EQ(INVALID, validator.AddBytes(byte_span_from_cstring("a")));
validator.Reset();
- EXPECT_EQ(VALID_ENDPOINT,
- validator.AddBytes(base::as_bytes(base::make_span("a", 1u))));
+ EXPECT_EQ(VALID_ENDPOINT, validator.AddBytes(byte_span_from_cstring("a")));
}
TEST_F(StreamingUtf8ValidatorSingleSequenceTest, Valid) {
diff --git a/base/immediate_crash_unittest.cc b/base/immediate_crash_unittest.cc
index a3dbc802..2fe57bc 100644
--- a/base/immediate_crash_unittest.cc
+++ b/base/immediate_crash_unittest.cc
@@ -150,8 +150,9 @@
const Instruction* const start = static_cast<Instruction*>(std::min(a, b));
const Instruction* const end = static_cast<Instruction*>(std::max(a, b));
- for (const Instruction& instruction : make_span(start, end))
+ for (const Instruction& instruction : span(start, end)) {
body->push_back(instruction);
+ }
}
#if defined(OFFICIAL_BUILD)
@@ -207,7 +208,7 @@
// code will falsely exit early, having not found the real expected crash
// sequence, so this may not adequately ensure that the immediate crash
// sequence is present. We do check when not under coverage, at least.
- return DropUntilMatch(instructions, base::make_span(kRequiredBody));
+ return DropUntilMatch(instructions, span(kRequiredBody));
#else
return instructions;
#endif // USE_CLANG_COVERAGE || BUILDFLAG(CLANG_PROFILING)
diff --git a/base/json/json_writer_unittest.cc b/base/json/json_writer_unittest.cc
index 6e1c1ae..e24ed3c 100644
--- a/base/json/json_writer_unittest.cc
+++ b/base/json/json_writer_unittest.cc
@@ -107,7 +107,7 @@
}
TEST(JsonWriterTest, BinaryValues) {
- const auto kBinaryData = base::as_bytes(base::make_span("asdf", 4u));
+ const auto kBinaryData = byte_span_from_cstring("asdf");
// Binary values should return errors unless suppressed via the
// `OPTIONS_OMIT_BINARY_VALUES` flag.
diff --git a/base/memory/platform_shared_memory_mapper_android.cc b/base/memory/platform_shared_memory_mapper_android.cc
index c1cf53e..4bde5375 100644
--- a/base/memory/platform_shared_memory_mapper_android.cc
+++ b/base/memory/platform_shared_memory_mapper_android.cc
@@ -33,7 +33,7 @@
return std::nullopt;
}
- return make_span(static_cast<uint8_t*>(address), size);
+ return span(static_cast<uint8_t*>(address), size);
}
void PlatformSharedMemoryMapper::Unmap(span<uint8_t> mapping) {
diff --git a/base/memory/platform_shared_memory_mapper_fuchsia.cc b/base/memory/platform_shared_memory_mapper_fuchsia.cc
index db6bd7c..64b3ce2 100644
--- a/base/memory/platform_shared_memory_mapper_fuchsia.cc
+++ b/base/memory/platform_shared_memory_mapper_fuchsia.cc
@@ -32,7 +32,7 @@
return std::nullopt;
}
- return make_span(reinterpret_cast<uint8_t*>(addr), size);
+ return span(reinterpret_cast<uint8_t*>(addr), size);
}
void PlatformSharedMemoryMapper::Unmap(span<uint8_t> mapping) {
diff --git a/base/memory/platform_shared_memory_mapper_posix.cc b/base/memory/platform_shared_memory_mapper_posix.cc
index 192f5d17..5bb3fb4 100644
--- a/base/memory/platform_shared_memory_mapper_posix.cc
+++ b/base/memory/platform_shared_memory_mapper_posix.cc
@@ -30,7 +30,7 @@
return std::nullopt;
}
- return make_span(static_cast<uint8_t*>(address), size);
+ return span(static_cast<uint8_t*>(address), size);
}
void PlatformSharedMemoryMapper::Unmap(span<uint8_t> mapping) {
diff --git a/base/memory/platform_shared_memory_mapper_win.cc b/base/memory/platform_shared_memory_mapper_win.cc
index eef28ad..3904974e 100644
--- a/base/memory/platform_shared_memory_mapper_win.cc
+++ b/base/memory/platform_shared_memory_mapper_win.cc
@@ -49,8 +49,7 @@
return std::nullopt;
}
- return make_span(static_cast<uint8_t*>(address),
- GetMemorySectionSize(address));
+ return span(static_cast<uint8_t*>(address), GetMemorySectionSize(address));
}
void PlatformSharedMemoryMapper::Unmap(span<uint8_t> mapping) {
diff --git a/base/memory/shared_memory_mapping.cc b/base/memory/shared_memory_mapping.cc
index 53938f46..edf8123 100644
--- a/base/memory/shared_memory_mapping.cc
+++ b/base/memory/shared_memory_mapping.cc
@@ -73,8 +73,7 @@
size_t adjusted_size =
mapped_span_.size() +
static_cast<size_t>(mapped_span_.data() - aligned_data);
- span<uint8_t> span_to_unmap = make_span(aligned_data, adjusted_size);
- mapper->Unmap(span_to_unmap);
+ mapper->Unmap(span(aligned_data, adjusted_size));
}
ReadOnlySharedMemoryMapping::ReadOnlySharedMemoryMapping() = default;
diff --git a/base/metrics/persistent_histogram_allocator.cc b/base/metrics/persistent_histogram_allocator.cc
index d6cf8c6..825c117 100644
--- a/base/metrics/persistent_histogram_allocator.cc
+++ b/base/metrics/persistent_histogram_allocator.cc
@@ -225,8 +225,8 @@
// |sample_map_records|, up until |until_value| (if applicable).
std::vector<PersistentMemoryAllocator::Reference> new_references;
CHECK_GE(found_records.size(), sample_map_records->seen_);
- auto new_found_records = base::make_span(found_records)
- .subspan(/*offset=*/sample_map_records->seen_);
+ auto new_found_records =
+ span(found_records).subspan(/*offset=*/sample_map_records->seen_);
new_references.reserve(new_found_records.size());
for (const auto& new_record : new_found_records) {
new_references.push_back(new_record.reference);
diff --git a/base/metrics/persistent_memory_allocator.cc b/base/metrics/persistent_memory_allocator.cc
index 9e5f585..269df891 100644
--- a/base/metrics/persistent_memory_allocator.cc
+++ b/base/metrics/persistent_memory_allocator.cc
@@ -1317,7 +1317,7 @@
DUMP_WILL_BE_NOTREACHED();
return span<uint8_t>();
}
- return make_span(mem + offset_, size_ - offset_);
+ return span(mem + offset_, size_ - offset_);
}
} // namespace base
diff --git a/base/metrics/persistent_memory_allocator.h b/base/metrics/persistent_memory_allocator.h
index 3ab70be..0265d26f 100644
--- a/base/metrics/persistent_memory_allocator.h
+++ b/base/metrics/persistent_memory_allocator.h
@@ -946,8 +946,8 @@
// will result.
CHECK_EQ(offset_ % alignof(T), 0u);
span<uint8_t> untyped = GetUntyped();
- return make_span(reinterpret_cast<T*>(untyped.data()),
- untyped.size() / sizeof(T));
+ return span(reinterpret_cast<T*>(untyped.data()),
+ untyped.size() / sizeof(T));
}
// Gets the internal reference value. If this returns a non-zero value then
diff --git a/base/metrics/sample_vector.h b/base/metrics/sample_vector.h
index 03e3bacb..c92c965 100644
--- a/base/metrics/sample_vector.h
+++ b/base/metrics/sample_vector.h
@@ -102,7 +102,7 @@
if (data == nullptr) {
return std::nullopt;
}
- return std::make_optional(make_span(data, counts_size_));
+ return span(data, counts_size_);
}
std::optional<span<const HistogramBase::AtomicCount>> counts() const {
@@ -111,7 +111,7 @@
if (data == nullptr) {
return std::nullopt;
}
- return std::make_optional(make_span(data, counts_size_));
+ return span(data, counts_size_);
}
void set_counts(span<HistogramBase::AtomicCount> counts) const {
diff --git a/base/pickle.cc b/base/pickle.cc
index c2755cb..d5031bc 100644
--- a/base/pickle.cc
+++ b/base/pickle.cc
@@ -213,14 +213,14 @@
return ReadBytes(data, *length);
}
-std::optional<base::span<const uint8_t>> PickleIterator::ReadData() {
+std::optional<span<const uint8_t>> PickleIterator::ReadData() {
const char* ptr;
size_t length;
if (!ReadData(&ptr, &length))
return std::nullopt;
- return base::as_bytes(base::make_span(ptr, length));
+ return as_bytes(span(ptr, length));
}
bool PickleIterator::ReadBytes(const char** data, size_t length) {
@@ -357,7 +357,7 @@
}
void Pickle::WriteBytes(const void* data, size_t length) {
- WriteBytesCommon(make_span(static_cast<const uint8_t*>(data), length));
+ WriteBytesCommon(span(static_cast<const uint8_t*>(data), length));
}
void Pickle::WriteBytes(span<const uint8_t> data) {
@@ -449,7 +449,7 @@
template <size_t length>
void Pickle::WriteBytesStatic(const void* data) {
- WriteBytesCommon(make_span(static_cast<const uint8_t*>(data), length));
+ WriteBytesCommon(span(static_cast<const uint8_t*>(data), length));
}
template void Pickle::WriteBytesStatic<2>(const void* data);
diff --git a/base/pickle.h b/base/pickle.h
index fe98ce67..69a894d 100644
--- a/base/pickle.h
+++ b/base/pickle.h
@@ -306,7 +306,7 @@
}
span<const uint8_t> payload_bytes() const {
- return as_bytes(make_span(payload(), payload_size()));
+ return as_bytes(span(payload(), payload_size()));
}
protected:
diff --git a/base/profiler/chrome_unwind_info_android_unittest.cc b/base/profiler/chrome_unwind_info_android_unittest.cc
index 2785925..39ede40 100644
--- a/base/profiler/chrome_unwind_info_android_unittest.cc
+++ b/base/profiler/chrome_unwind_info_android_unittest.cc
@@ -86,13 +86,13 @@
ASSERT_EQ(&data[256], reinterpret_cast<const uint8_t*>(
&unwind_info.unwind_instruction_table[0]));
- ExpectSpanSizeAndContentsEqual(unwind_info.page_table, make_span(page_table));
+ ExpectSpanSizeAndContentsEqual(unwind_info.page_table, span(page_table));
ExpectSpanSizeAndContentsEqual(unwind_info.function_table,
- make_span(function_table));
+ span(function_table));
ExpectSpanSizeAndContentsEqual(unwind_info.function_offset_table,
- make_span(function_offset_table));
+ span(function_offset_table));
ExpectSpanSizeAndContentsEqual(unwind_info.unwind_instruction_table,
- make_span(unwind_instruction_table));
+ span(unwind_instruction_table));
}
} // namespace base
diff --git a/base/strings/strcat.h b/base/strings/strcat.h
index b2a76568..8997593 100644
--- a/base/strings/strcat.h
+++ b/base/strings/strcat.h
@@ -68,12 +68,12 @@
// Initializer list forwards to the array version.
inline std::string StrCat(std::initializer_list<std::string_view> pieces) {
- return StrCat(make_span(pieces));
+ return StrCat(span(pieces));
}
inline std::u16string StrCat(
std::initializer_list<std::u16string_view> pieces) {
- return StrCat(make_span(pieces));
+ return StrCat(span(pieces));
}
// StrAppend -------------------------------------------------------------------
@@ -95,12 +95,12 @@
// Initializer list forwards to the array version.
inline void StrAppend(std::string* dest,
std::initializer_list<std::string_view> pieces) {
- StrAppend(dest, make_span(pieces));
+ StrAppend(dest, span(pieces));
}
inline void StrAppend(std::u16string* dest,
std::initializer_list<std::u16string_view> pieces) {
- StrAppend(dest, make_span(pieces));
+ StrAppend(dest, span(pieces));
}
} // namespace base
diff --git a/base/strings/strcat_win.h b/base/strings/strcat_win.h
index e230373f..9bd7007 100644
--- a/base/strings/strcat_win.h
+++ b/base/strings/strcat_win.h
@@ -22,7 +22,7 @@
inline void StrAppend(std::wstring* dest,
std::initializer_list<std::wstring_view> pieces) {
- StrAppend(dest, make_span(pieces));
+ StrAppend(dest, span(pieces));
}
[[nodiscard]] BASE_EXPORT std::wstring StrCat(
@@ -30,7 +30,7 @@
[[nodiscard]] BASE_EXPORT std::wstring StrCat(span<const std::wstring> pieces);
inline std::wstring StrCat(std::initializer_list<std::wstring_view> pieces) {
- return StrCat(make_span(pieces));
+ return StrCat(span(pieces));
}
} // namespace base
diff --git a/base/test/launcher/unit_test_launcher.cc b/base/test/launcher/unit_test_launcher.cc
index 203faa9..79bcac6c 100644
--- a/base/test/launcher/unit_test_launcher.cc
+++ b/base/test/launcher/unit_test_launcher.cc
@@ -284,8 +284,7 @@
// Fuzztest requires a narrow command-line.
CHECK(*argc >= 0);
const auto argc_s = static_cast<size_t>(*argc);
- base::span<wchar_t*> wide_command_line =
- UNSAFE_BUFFERS(base::make_span(argv, argc_s));
+ span<wchar_t*> wide_command_line = UNSAFE_BUFFERS(span(argv, argc_s));
std::vector<std::string> narrow_command_line;
std::vector<char*> narrow_command_line_pointers;
narrow_command_line.reserve(argc_s);
diff --git a/base/token.h b/base/token.h
index d90ceeb..e52c9747 100644
--- a/base/token.h
+++ b/base/token.h
@@ -48,9 +48,7 @@
constexpr bool is_zero() const { return words_[0] == 0 && words_[1] == 0; }
- span<const uint8_t, 16> AsBytes() const {
- return as_bytes(make_span(words_));
- }
+ span<const uint8_t, 16> AsBytes() const { return as_byte_span(words_); }
friend constexpr auto operator<=>(const Token& lhs,
const Token& rhs) = default;
diff --git a/base/trace_event/category_registry.cc b/base/trace_event/category_registry.cc
index d094dfb..0ac653e 100644
--- a/base/trace_event/category_registry.cc
+++ b/base/trace_event/category_registry.cc
@@ -134,12 +134,12 @@
}
// static
-base::span<TraceCategory> CategoryRegistry::GetAllCategories() {
+span<TraceCategory> CategoryRegistry::GetAllCategories() {
// The |categories_| array is append only. We have to only guarantee to
// not return an index to a category which is being initialized by
// GetOrCreateCategoryByName().
size_t category_index = category_index_.load(std::memory_order_acquire);
- return base::make_span(categories_).first(category_index);
+ return span(categories_).first(category_index);
}
// static
diff --git a/base/trace_event/cfi_backtrace_android_unittest.cc b/base/trace_event/cfi_backtrace_android_unittest.cc
index 9427078..d40f6ac6 100644
--- a/base/trace_event/cfi_backtrace_android_unittest.cc
+++ b/base/trace_event/cfi_backtrace_android_unittest.cc
@@ -88,7 +88,7 @@
0xdc, 0x40, 0x1, 0x4, 0x2e};
FilePath temp_path;
CreateTemporaryFile(&temp_path);
- EXPECT_TRUE(WriteFile(temp_path, base::as_bytes(base::make_span(input))));
+ EXPECT_TRUE(WriteFile(temp_path, as_byte_span(input)));
unwinder->cfi_mmap_.reset(new MemoryMappedFile());
ASSERT_TRUE(unwinder->cfi_mmap_->Initialize(temp_path));
diff --git a/base/trace_event/heap_profiler_allocation_context.cc b/base/trace_event/heap_profiler_allocation_context.cc
index 9c38bbe..ed4d619f 100644
--- a/base/trace_event/heap_profiler_allocation_context.cc
+++ b/base/trace_event/heap_profiler_allocation_context.cc
@@ -73,8 +73,8 @@
for (size_t i = 0; i != backtrace.frame_count; ++i) {
values[i] = backtrace.frames[i].value;
}
- auto values_span = base::make_span(values).first(backtrace.frame_count);
- return base::PersistentHash(base::as_bytes(values_span));
+ return base::PersistentHash(
+ base::as_bytes(base::span(values).first(backtrace.frame_count)));
}
size_t hash<AllocationContext>::operator()(const AllocationContext& ctx) const {
diff --git a/base/uuid_unittest.cc b/base/uuid_unittest.cc
index f7e44820e8..d9b04ca 100644
--- a/base/uuid_unittest.cc
+++ b/base/uuid_unittest.cc
@@ -198,13 +198,11 @@
0xfffffffffffffffcull};
const Uuid guid1a =
- Uuid::FormatRandomDataAsV4ForTesting(as_bytes(make_span(bytes1a)));
+ Uuid::FormatRandomDataAsV4ForTesting(as_byte_span(bytes1a));
const Uuid guid1b =
- Uuid::FormatRandomDataAsV4ForTesting(as_bytes(make_span(bytes1b)));
- const Uuid guid2 =
- Uuid::FormatRandomDataAsV4ForTesting(as_bytes(make_span(bytes2)));
- const Uuid guid3 =
- Uuid::FormatRandomDataAsV4ForTesting(as_bytes(make_span(bytes3)));
+ Uuid::FormatRandomDataAsV4ForTesting(as_byte_span(bytes1b));
+ const Uuid guid2 = Uuid::FormatRandomDataAsV4ForTesting(as_byte_span(bytes2));
+ const Uuid guid3 = Uuid::FormatRandomDataAsV4ForTesting(as_byte_span(bytes3));
EXPECT_TRUE(guid1a.is_valid());
EXPECT_TRUE(guid1b.is_valid());
diff --git a/base/win/access_token.cc b/base/win/access_token.cc
index bf5482a9..d9564cf 100644
--- a/base/win/access_token.cc
+++ b/base/win/access_token.cc
@@ -630,9 +630,8 @@
return false;
}
- for (auto privileges = base::make_span(&token_privileges->Privileges[0],
- token_privileges->PrivilegeCount);
- auto& privilege : privileges) {
+ for (auto& privilege : span(&token_privileges->Privileges[0],
+ token_privileges->PrivilegeCount)) {
privilege.Attributes = SE_PRIVILEGE_REMOVED;
}
return ::AdjustTokenPrivileges(
diff --git a/base/win/pe_image_reader.cc b/base/win/pe_image_reader.cc
index 85a5456e..8386735 100644
--- a/base/win/pe_image_reader.cc
+++ b/base/win/pe_image_reader.cc
@@ -107,7 +107,7 @@
}
span<const uint8_t> PeImageReader::GetOptionalHeaderData() {
- return make_span(GetOptionalHeaderStart(), GetOptionalHeaderSize());
+ return span(GetOptionalHeaderStart(), GetOptionalHeaderSize());
}
size_t PeImageReader::GetNumberOfSections() {
@@ -155,7 +155,7 @@
debug_directory_data[index * sizeof(IMAGE_DEBUG_DIRECTORY)]);
const uint8_t* debug_data = nullptr;
if (GetStructureAt(entry.PointerToRawData, entry.SizeOfData, &debug_data)) {
- raw_data = make_span(debug_data, entry.SizeOfData);
+ raw_data = span(debug_data, entry.SizeOfData);
}
return &entry;
}