0

[cleanup] Replace base::ranges with std::ranges: sql/

Done entirely with `git grep` and `sed` + `git cl format`, no
hand-editing.

Bug: 386918226
Change-Id: Ic4bae3c955936455ce0112a7e5d4efe806f5b9b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6196286
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Etienne Bergeron <etienneb@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1411795}
This commit is contained in:
Peter Kasting
2025-01-27 11:50:47 -08:00
committed by Chromium LUCI CQ
parent 413ebc5984
commit 3f01b691ee
5 changed files with 17 additions and 17 deletions

@@ -14,6 +14,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <algorithm>
#include <cinttypes> #include <cinttypes>
#include <memory> #include <memory>
#include <optional> #include <optional>
@@ -39,7 +40,6 @@
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/notimplemented.h" #include "base/notimplemented.h"
#include "base/notreached.h" #include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "base/strings/cstring_view.h" #include "base/strings/cstring_view.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
@@ -180,8 +180,8 @@ bool ValidAttachmentPoint(std::string_view attachment_point) {
// Chrome's constraint is easy to remember, and sufficient for the few // Chrome's constraint is easy to remember, and sufficient for the few
// existing use cases. ATTACH is a discouraged feature, so no new use cases // existing use cases. ATTACH is a discouraged feature, so no new use cases
// are expected. // are expected.
return base::ranges::all_of(attachment_point, return std::ranges::all_of(attachment_point,
[](char ch) { return base::IsAsciiLower(ch); }); [](char ch) { return base::IsAsciiLower(ch); });
} }
std::string AsUTF8ForSQL(const base::FilePath& path) { std::string AsUTF8ForSQL(const base::FilePath& path) {

@@ -14,6 +14,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <algorithm>
#include <memory> #include <memory>
#include <optional> #include <optional>
#include <string> #include <string>
@@ -33,7 +34,6 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/raw_ptr.h" #include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "base/strings/cstring_view.h" #include "base/strings/cstring_view.h"

@@ -12,6 +12,7 @@
#include <fuzzer/FuzzedDataProvider.h> #include <fuzzer/FuzzedDataProvider.h>
#include <algorithm>
#include <cstdint> #include <cstdint>
#include <cstdlib> #include <cstdlib>
#include <ios> #include <ios>
@@ -34,7 +35,6 @@
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/ranges/algorithm.h"
#include "base/strings/cstring_view.h" #include "base/strings/cstring_view.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
@@ -75,7 +75,7 @@ std::optional<base::CommandLine> GetCommandLine() {
additional_args, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); additional_args, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
#if BUILDFLAG(IS_WIN) #if BUILDFLAG(IS_WIN)
std::vector<std::wstring> wargv(argv.size()); std::vector<std::wstring> wargv(argv.size());
base::ranges::transform( std::ranges::transform(
argv.begin(), argv.end(), wargv.begin(), argv.begin(), argv.end(), wargv.begin(),
[](std::string str) { return std::wstring(str.begin(), str.end()); }); [](std::string str) { return std::wstring(str.begin(), str.end()); });
return base::CommandLine::FromArgvWithoutProgram(wargv); return base::CommandLine::FromArgvWithoutProgram(wargv);
@@ -259,10 +259,10 @@ DEFINE_PROTO_FUZZER(const sql_fuzzers::RecoveryFuzzerTestCase& fuzzer_input) {
// //
// TODO: A slight improvement would be to filter out individual "ATTACH // TODO: A slight improvement would be to filter out individual "ATTACH
// DATABASE" queries rather than throwing away the whole test case. // DATABASE" queries rather than throwing away the whole test case.
if (base::ranges::any_of(fuzzer_input.queries().extra_queries(), if (std::ranges::any_of(fuzzer_input.queries().extra_queries(),
&sql_query_grammar::SQLQuery::has_attach_db) || &sql_query_grammar::SQLQuery::has_attach_db) ||
base::ranges::any_of(fuzzer_input.queries_after_open().extra_queries(), std::ranges::any_of(fuzzer_input.queries_after_open().extra_queries(),
&sql_query_grammar::SQLQuery::has_attach_db)) { &sql_query_grammar::SQLQuery::has_attach_db)) {
return; return;
} }

@@ -11,6 +11,7 @@
#include <stddef.h> #include <stddef.h>
#include <algorithm>
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <tuple> #include <tuple>
@@ -24,7 +25,6 @@
#include "base/functional/callback_forward.h" #include "base/functional/callback_forward.h"
#include "base/functional/callback_helpers.h" #include "base/functional/callback_helpers.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/test/bind.h" #include "base/test/bind.h"
@@ -237,7 +237,7 @@ TEST_P(SqlRecoveryTest, RecoverCorruptTable) {
ASSERT_EQ(db_.page_size(), kDbPageSize) ASSERT_EQ(db_.page_size(), kDbPageSize)
<< "Page overflow relies on specific size"; << "Page overflow relies on specific size";
large_buffer.resize(kDbPageSize * 2); large_buffer.resize(kDbPageSize * 2);
base::ranges::fill(large_buffer, '8'); std::ranges::fill(large_buffer, '8');
sql::Statement insert(db_.GetUniqueStatement( sql::Statement insert(db_.GetUniqueStatement(
"INSERT INTO rows(indexed,unindexed,filler) VALUES(8,8,?)")); "INSERT INTO rows(indexed,unindexed,filler) VALUES(8,8,?)"));
insert.BindBlob(0, large_buffer); insert.BindBlob(0, large_buffer);
@@ -477,7 +477,7 @@ void TestRecoverDatabase(Database& db,
// Save aside a copy of the original schema, verifying that it has the created // Save aside a copy of the original schema, verifying that it has the created
// items plus the sqlite_sequence table. // items plus the sqlite_sequence table.
const std::string original_schema = GetSchema(&db); const std::string original_schema = GetSchema(&db);
ASSERT_EQ(with_meta ? 6 : 4, base::ranges::count(original_schema, '\n')) ASSERT_EQ(with_meta ? 6 : 4, std::ranges::count(original_schema, '\n'))
<< original_schema; << original_schema;
static constexpr char kTable1Sql[] = "SELECT * FROM table1 ORDER BY 1"; static constexpr char kTable1Sql[] = "SELECT * FROM table1 ORDER BY 1";
@@ -659,7 +659,7 @@ TEST_P(SqlRecoveryTest, RecoverDatabaseWithView) {
// Save aside a copy of the original schema, verifying that it has the created // Save aside a copy of the original schema, verifying that it has the created
// items plus the sqlite_sequence table. // items plus the sqlite_sequence table.
const std::string original_schema = GetSchema(&db); const std::string original_schema = GetSchema(&db);
ASSERT_EQ(4, base::ranges::count(original_schema, '\n')) << original_schema; ASSERT_EQ(4, std::ranges::count(original_schema, '\n')) << original_schema;
// Database handle is valid before recovery, poisoned after. // Database handle is valid before recovery, poisoned after.
static constexpr char kTrivialSql[] = "SELECT COUNT(*) FROM sqlite_schema"; static constexpr char kTrivialSql[] = "SELECT COUNT(*) FROM sqlite_schema";

@@ -4,6 +4,7 @@
#include "sql/sqlite_result_code.h" #include "sql/sqlite_result_code.h"
#include <algorithm>
#include <cstddef> #include <cstddef>
#include <ostream> // Needed to compile CHECK() with operator <<. #include <ostream> // Needed to compile CHECK() with operator <<.
#include <ranges> #include <ranges>
@@ -16,7 +17,6 @@
#include "base/dcheck_is_on.h" #include "base/dcheck_is_on.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/ranges/algorithm.h"
#include "sql/sqlite_result_code_values.h" #include "sql/sqlite_result_code_values.h"
#include "third_party/sqlite/sqlite3.h" #include "third_party/sqlite/sqlite3.h"
@@ -313,7 +313,7 @@ file lock requests"
// Returns an entry in kResultCodeMapping or kUnknownResultCodeMappingEntry. // Returns an entry in kResultCodeMapping or kUnknownResultCodeMappingEntry.
// CHECKs if the `sqlite_result_code` is not in the mapping table. // CHECKs if the `sqlite_result_code` is not in the mapping table.
SqliteResultCodeMappingEntry FindResultCode(int sqlite_result_code) { SqliteResultCodeMappingEntry FindResultCode(int sqlite_result_code) {
const auto* mapping_it = base::ranges::find_if( const auto* mapping_it = std::ranges::find_if(
kResultCodeMapping, kResultCodeMapping,
[&sqlite_result_code](SqliteResultCodeMappingEntry rhs) { [&sqlite_result_code](SqliteResultCodeMappingEntry rhs) {
return sqlite_result_code == rhs.result_code; return sqlite_result_code == rhs.result_code;
@@ -415,7 +415,7 @@ std::ostream& operator<<(std::ostream& os, SqliteErrorCode sqlite_error_code) {
void CheckSqliteLoggedResultCodeForTesting() { void CheckSqliteLoggedResultCodeForTesting() {
// Ensure that error codes are alphabetical. // Ensure that error codes are alphabetical.
const auto* unordered_it = base::ranges::adjacent_find( const auto* unordered_it = std::ranges::adjacent_find(
kResultCodeMapping, kResultCodeMapping,
[](SqliteResultCodeMappingEntry lhs, SqliteResultCodeMappingEntry rhs) { [](SqliteResultCodeMappingEntry lhs, SqliteResultCodeMappingEntry rhs) {
return lhs.result_code >= rhs.result_code; return lhs.result_code >= rhs.result_code;