Hash :
a02670d6
Author :
Date :
2025-08-26T20:41:16
Move unsafe buffers inside header guard macros While this is exactly opposite of what Chromium has chosen to do, there is an issue with clang-format trying to indent preprocessor directives four spaces relative to include guard. This is because Angle's .clang-format file specifies IndentPPDirectives: AfterHash but Chromium's does not. The current placement is sufficient to throw off clang-format's guard detection since the guard macro no longer covers the entire file. Bug: b/436880895 Change-Id: Ic6b99c8cef6213939cdf9b42af8730e1eb423065 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6885892 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org> Auto-Submit: Tom Sepez <tsepez@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
//
// Copyright 2025 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Span.h:
// Basic implementation of C++20's span.
//
#ifndef COMMON_SPAN_H_
#define COMMON_SPAN_H_
#ifdef UNSAFE_BUFFERS_BUILD
# pragma allow_unsafe_buffers
#endif
#include <type_traits>
#include "common/log_utils.h"
namespace angle
{
// Basic implementation of C++20's span.
// See the reference for std::span here: https://en.cppreference.com/w/cpp/container/span
template <typename T>
class Span
{
public:
typedef size_t size_type;
constexpr Span() = default;
constexpr Span(T *ptr, size_type size) : mData(ptr), mSize(size) {}
template <typename V,
typename = std::enable_if_t<std::remove_reference_t<V>::is_pool_allocated>>
constexpr Span(V &&vec) : mData(vec.data()), mSize(vec.size())
{}
template <typename V,
typename = std::enable_if_t<std::remove_reference_t<V>::is_pool_allocated>>
constexpr Span &operator=(V &&vec)
{
mData = vec.data();
mSize = vec.size();
return *this;
}
constexpr bool operator==(const Span &that) const
{
if (mSize != that.mSize)
{
return false;
}
if (mData == that.mData)
{
return true;
}
for (size_type index = 0; index < mSize; ++index)
{
if (mData[index] != that.mData[index])
{
return false;
}
}
return true;
}
constexpr bool operator!=(const Span &that) const { return !(*this == that); }
constexpr T *data() const { return mData; }
constexpr size_type size() const { return mSize; }
constexpr bool empty() const { return mSize == 0; }
constexpr T &operator[](size_type index) const { return mData[index]; }
constexpr T &front() const { return mData[0]; }
constexpr T &back() const { return mData[mSize - 1]; }
constexpr T *begin() const { return mData; }
constexpr T *end() const { return mData + mSize; }
constexpr std::reverse_iterator<T *> rbegin() const
{
return std::make_reverse_iterator(end());
}
constexpr std::reverse_iterator<T *> rend() const
{
return std::make_reverse_iterator(begin());
}
constexpr Span first(size_type count) const
{
ASSERT(count <= mSize);
return count == 0 ? Span() : Span(mData, count);
}
constexpr Span last(size_type count) const
{
ASSERT(count <= mSize);
return count == 0 ? Span() : Span(mData + mSize - count, count);
}
constexpr Span subspan(size_type offset, size_type count) const
{
ASSERT(offset + count <= mSize);
return count == 0 ? Span() : Span(mData + offset, count);
}
private:
T *mData = nullptr;
size_t mSize = 0;
};
} // namespace angle
#endif // COMMON_SPAN_