Skip to content

Commit 3b17f28

Browse files
committed
ui: use std::span instead of std::basic_string_view<uint8_t>
The string classes are only defined for character types, and std::basic_string_view<uint8_t> has been removed now. See https://discourse.llvm.org/t/deprecating-std-string-t-for-non-character-t/66779. Cast std::span<T>::size() to size_t because the WIP std::span::size() has a ptrdiff_t return type instead of size_t. Bug: 175635923 Test: m MODULES-IN-frameworks-native-libs-ui Change-Id: I156f1032191c74cc7c3f6b0cdb7dc0393e9e906f
1 parent 66bbdd2 commit 3b17f28

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

libs/ui/DisplayIdentification.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <cctype>
2222
#include <numeric>
2323
#include <optional>
24+
#include <span>
2425

2526
#include <log/log.h>
2627

@@ -81,15 +82,16 @@ uint64_t hash64Len0To16(const char* s, uint64_t len) {
8182
return k2;
8283
}
8384

84-
using byte_view = std::basic_string_view<uint8_t>;
85+
using byte_view = std::span<const uint8_t>;
8586

8687
constexpr size_t kEdidBlockSize = 128;
8788
constexpr size_t kEdidHeaderLength = 5;
8889

8990
constexpr uint16_t kVirtualEdidManufacturerId = 0xffffu;
9091

9192
std::optional<uint8_t> getEdidDescriptorType(const byte_view& view) {
92-
if (view.size() < kEdidHeaderLength || view[0] || view[1] || view[2] || view[4]) {
93+
if (static_cast<size_t>(view.size()) < kEdidHeaderLength || view[0] || view[1] || view[2] ||
94+
view[4]) {
9395
return {};
9496
}
9597

@@ -164,7 +166,7 @@ Cea861ExtensionBlock parseCea861Block(const byte_view& block) {
164166
constexpr size_t kDataBlockHeaderSize = 1;
165167
const size_t dataBlockSize = bodyLength + kDataBlockHeaderSize;
166168

167-
if (block.size() < dataBlockOffset + dataBlockSize) {
169+
if (static_cast<size_t>(block.size()) < dataBlockOffset + dataBlockSize) {
168170
ALOGW("Invalid EDID: CEA 861 data block is truncated.");
169171
break;
170172
}
@@ -264,7 +266,7 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) {
264266
}
265267

266268
byte_view view(edid.data(), edid.size());
267-
view.remove_prefix(kDescriptorOffset);
269+
view = view.subspan(kDescriptorOffset);
268270

269271
std::string_view displayName;
270272
std::string_view serialNumber;
@@ -274,13 +276,13 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) {
274276
constexpr size_t kDescriptorLength = 18;
275277

276278
for (size_t i = 0; i < kDescriptorCount; i++) {
277-
if (view.size() < kDescriptorLength) {
279+
if (static_cast<size_t>(view.size()) < kDescriptorLength) {
278280
break;
279281
}
280282

281283
if (const auto type = getEdidDescriptorType(view)) {
282284
byte_view descriptor(view.data(), kDescriptorLength);
283-
descriptor.remove_prefix(kEdidHeaderLength);
285+
descriptor = descriptor.subspan(kEdidHeaderLength);
284286

285287
switch (*type) {
286288
case 0xfc:
@@ -295,7 +297,7 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) {
295297
}
296298
}
297299

298-
view.remove_prefix(kDescriptorLength);
300+
view = view.subspan(kDescriptorLength);
299301
}
300302

301303
std::string_view modelString = displayName;
@@ -327,8 +329,8 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) {
327329
const size_t numExtensions = edid[kNumExtensionsOffset];
328330
view = byte_view(edid.data(), edid.size());
329331
for (size_t blockNumber = 1; blockNumber <= numExtensions; blockNumber++) {
330-
view.remove_prefix(kEdidBlockSize);
331-
if (view.size() < kEdidBlockSize) {
332+
view = view.subspan(kEdidBlockSize);
333+
if (static_cast<size_t>(view.size()) < kEdidBlockSize) {
332334
ALOGW("Invalid EDID: block %zu is truncated.", blockNumber);
333335
break;
334336
}

0 commit comments

Comments
 (0)