Skip to content

Commit 4e6c895

Browse files
committed
Use more std::span arguments
1 parent 6608bca commit 4e6c895

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+167
-156
lines changed

Source/Core/Common/Assembler/GekkoLexer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ void Lexer::EatAndReset()
486486
SetIdentifierMatchRule(IdentifierMatchRule::Typical);
487487
}
488488

489-
std::optional<std::string_view> Lexer::RunDfa(const std::vector<DfaNode>& dfa) const
489+
std::optional<std::string_view> Lexer::RunDfa(std::span<const DfaNode> dfa) const
490490
{
491491
size_t dfa_index = 0;
492492
bool transition_found;

Source/Core/Common/Assembler/GekkoLexer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <array>
88
#include <deque>
99
#include <optional>
10+
#include <span>
1011
#include <string_view>
1112
#include <vector>
1213

@@ -166,7 +167,7 @@ class Lexer
166167
}
167168

168169
private:
169-
std::optional<std::string_view> RunDfa(const std::vector<DfaNode>& dfa) const;
170+
std::optional<std::string_view> RunDfa(std::span<const DfaNode> dfa) const;
170171
void SkipWs() const;
171172
void FeedbackTokens() const;
172173
bool IdentifierHeadExtra(char h) const;

Source/Core/Common/Debug/Watches.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void Watches::RemoveWatch(std::size_t index)
8989
m_watches.erase(m_watches.begin() + index);
9090
}
9191

92-
void Watches::LoadFromStrings(const std::vector<std::string>& watches)
92+
void Watches::LoadFromStrings(std::span<const std::string> watches)
9393
{
9494
for (const std::string& watch : watches)
9595
{

Source/Core/Common/Debug/Watches.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#pragma once
55

66
#include <cstddef>
7+
#include <span>
78
#include <string>
89
#include <vector>
910

@@ -42,7 +43,7 @@ class Watches
4243
void DisableWatch(std::size_t index);
4344
bool HasEnabledWatch(u32 address) const;
4445
void RemoveWatch(std::size_t index);
45-
void LoadFromStrings(const std::vector<std::string>& watches);
46+
void LoadFromStrings(std::span<const std::string> watches);
4647
std::vector<std::string> SaveToStrings() const;
4748
void Clear();
4849

Source/Core/Common/HttpRequest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ HttpRequest::Response HttpRequest::Get(const std::string& url, const Headers& he
9696
return m_impl->Fetch(url, Impl::Method::GET, headers, nullptr, 0, codes);
9797
}
9898

99-
HttpRequest::Response HttpRequest::Post(const std::string& url, const std::vector<u8>& payload,
99+
HttpRequest::Response HttpRequest::Post(const std::string& url, std::span<const u8> payload,
100100
const Headers& headers, AllowedReturnCodes codes)
101101
{
102102
return m_impl->Fetch(url, Impl::Method::POST, headers, payload.data(), payload.size(), codes);
103103
}
104104

105-
HttpRequest::Response HttpRequest::Post(const std::string& url, const std::string& payload,
105+
HttpRequest::Response HttpRequest::Post(const std::string& url, std::string_view payload,
106106
const Headers& headers, AllowedReturnCodes codes)
107107
{
108108
return m_impl->Fetch(url, Impl::Method::POST, headers,

Source/Core/Common/HttpRequest.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <optional>
1111
#include <span>
1212
#include <string>
13+
#include <string_view>
1314
#include <vector>
1415

1516
#include "Common/CommonTypes.h"
@@ -50,9 +51,9 @@ class HttpRequest final
5051
std::string GetHeaderValue(std::string_view name) const;
5152
Response Get(const std::string& url, const Headers& headers = {},
5253
AllowedReturnCodes codes = AllowedReturnCodes::Ok_Only);
53-
Response Post(const std::string& url, const std::vector<u8>& payload, const Headers& headers = {},
54+
Response Post(const std::string& url, std::span<const u8> payload, const Headers& headers = {},
5455
AllowedReturnCodes codes = AllowedReturnCodes::Ok_Only);
55-
Response Post(const std::string& url, const std::string& payload, const Headers& headers = {},
56+
Response Post(const std::string& url, std::string_view payload, const Headers& headers = {},
5657
AllowedReturnCodes codes = AllowedReturnCodes::Ok_Only);
5758

5859
Response PostMultiform(const std::string& url, std::span<Multiform> multiform,

Source/Core/Common/Network.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ DHCPBody::DHCPBody(u32 transaction, const MACAddress& client_address, u32 new_ip
462462

463463
DHCPPacket::DHCPPacket() = default;
464464

465-
DHCPPacket::DHCPPacket(const std::vector<u8>& data)
465+
DHCPPacket::DHCPPacket(std::span<const u8> data)
466466
{
467467
if (data.size() < DHCPBody::SIZE)
468468
return;
@@ -489,13 +489,13 @@ DHCPPacket::DHCPPacket(const std::vector<u8>& data)
489489
}
490490
}
491491

492-
void DHCPPacket::AddOption(u8 fnc, const std::vector<u8>& params)
492+
void DHCPPacket::AddOption(u8 fnc, std::span<const u8> params)
493493
{
494494
if (params.size() > 255)
495495
return;
496496
std::vector<u8> opt = {fnc, u8(params.size())};
497497
opt.insert(opt.end(), params.begin(), params.end());
498-
options.emplace_back(std::move(opt));
498+
options.push_back(std::move(opt));
499499
}
500500

501501
std::vector<u8> DHCPPacket::Build() const
@@ -507,7 +507,7 @@ std::vector<u8> DHCPPacket::Build() const
507507
{
508508
result.insert(result.end(), opt.begin(), opt.end());
509509
}
510-
const std::vector<u8> no_option = {255, 0, 0, 0};
510+
constexpr auto no_option = std::to_array<u8>({255, 0, 0, 0});
511511
result.insert(result.end(), no_option.begin(), no_option.end());
512512

513513
return result;

Source/Core/Common/Network.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <array>
77
#include <optional>
8+
#include <span>
89
#include <string>
910
#include <string_view>
1011
#include <type_traits>
@@ -183,8 +184,8 @@ static_assert(sizeof(DHCPBody) == DHCPBody::SIZE);
183184
struct DHCPPacket
184185
{
185186
DHCPPacket();
186-
DHCPPacket(const std::vector<u8>& data);
187-
void AddOption(u8 fnc, const std::vector<u8>& params);
187+
DHCPPacket(std::span<const u8> data);
188+
void AddOption(u8 fnc, std::span<const u8> params);
188189
std::vector<u8> Build() const;
189190

190191
DHCPBody body;

Source/Core/Core/Boot/DolReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ DolReader::DolReader(const std::string& filename) : BootExecutableReader(filenam
3131

3232
DolReader::~DolReader() = default;
3333

34-
bool DolReader::Initialize(const std::vector<u8>& buffer)
34+
bool DolReader::Initialize(std::span<const u8> buffer)
3535
{
3636
if (buffer.size() < sizeof(SDolHeader) || buffer.size() > UINT32_MAX)
3737
return false;

Source/Core/Core/Boot/DolReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class DolReader final : public BootExecutableReader
6565
bool m_is_ancast;
6666

6767
// Copy sections to internal buffers
68-
bool Initialize(const std::vector<u8>& buffer);
68+
bool Initialize(std::span<const u8> buffer);
6969

7070
bool LoadAncastIntoMemory(Core::System& system) const;
7171
};

0 commit comments

Comments
 (0)