Skip to content

Commit

Permalink
Replace vector by span
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Sep 7, 2023
1 parent 111d693 commit 6a749df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
12 changes: 6 additions & 6 deletions cpp/devices/scsi_command_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,41 +97,41 @@ void scsi_command_util::AddAppleVendorModePage(map<int, vector<byte>>& pages, bo

// No changeable area
if (!changeable) {
const char APPLE_DATA[] = "APPLE COMPUTER, INC ";
constexpr const char APPLE_DATA[] = "APPLE COMPUTER, INC ";
memcpy(&pages[48].data()[2], APPLE_DATA, sizeof(APPLE_DATA));
}
}

int scsi_command_util::GetInt16(const vector<uint8_t>& buf, int offset)
int scsi_command_util::GetInt16(span <const uint8_t> buf, int offset)
{
assert(buf.size() > static_cast<size_t>(offset) + 1);

return (static_cast<int>(buf[offset]) << 8) | buf[offset + 1];
}

int scsi_command_util::GetInt16(const vector<int>& buf, int offset)
int scsi_command_util::GetInt16(span <const int> buf, int offset)
{
assert(buf.size() > static_cast<size_t>(offset) + 1);

return (buf[offset] << 8) | buf[offset + 1];
}

int scsi_command_util::GetInt24(const vector<int>& buf, int offset)
int scsi_command_util::GetInt24(span <const int> buf, int offset)
{
assert(buf.size() > static_cast<size_t>(offset) + 2);

return (buf[offset] << 16) | (buf[offset + 1] << 8) | buf[offset + 2];
}

uint32_t scsi_command_util::GetInt32(const vector<int>& buf, int offset)
uint32_t scsi_command_util::GetInt32(span <const int> buf, int offset)
{
assert(buf.size() > static_cast<size_t>(offset) + 3);

return (static_cast<uint32_t>(buf[offset]) << 24) | (static_cast<uint32_t>(buf[offset + 1]) << 16) |
(static_cast<uint32_t>(buf[offset + 2]) << 8) | static_cast<uint32_t>(buf[offset + 3]);
}

uint64_t scsi_command_util::GetInt64(const vector<int>& buf, int offset)
uint64_t scsi_command_util::GetInt64(span<const int> buf, int offset)
{
assert(buf.size() > static_cast<size_t>(offset) + 7);

Expand Down
13 changes: 7 additions & 6 deletions cpp/devices/scsi_command_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Copyright (C) 2022 Uwe Seimet
// Copyright (C) 2022-2023 Uwe Seimet
//
// Shared code for SCSI command implementations
//
Expand All @@ -12,6 +12,7 @@
#pragma once

#include "shared/scsi.h"
#include <span>
#include <vector>
#include <map>

Expand All @@ -25,11 +26,11 @@ namespace scsi_command_util
void EnrichFormatPage(map<int, vector<byte>>&, bool, int);
void AddAppleVendorModePage(map<int, vector<byte>>&, bool);

int GetInt16(const vector<uint8_t>&, int);
int GetInt16(const vector<int>&, int);
int GetInt24(const vector<int>&, int);
uint32_t GetInt32(const vector<int>&, int);
uint64_t GetInt64(const vector<int>&, int);
int GetInt16(span <const uint8_t>, int);
int GetInt16(span <const int>, int);
int GetInt24(span<const int>, int);
uint32_t GetInt32(span <const int>, int);
uint64_t GetInt64(span<const int>, int);
void SetInt16(vector<byte>&, int, int);
void SetInt32(vector<byte>&, int, uint32_t);
void SetInt16(vector<uint8_t>&, int, int);
Expand Down

0 comments on commit 6a749df

Please sign in to comment.