aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/containers/stack_array
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:17 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:17 +0300
commitd3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch)
treedd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/containers/stack_array
parent72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff)
downloadydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/containers/stack_array')
-rw-r--r--library/cpp/containers/stack_array/range_ops.cpp2
-rw-r--r--library/cpp/containers/stack_array/range_ops.h96
-rw-r--r--library/cpp/containers/stack_array/stack_array.cpp2
-rw-r--r--library/cpp/containers/stack_array/stack_array.h36
-rw-r--r--library/cpp/containers/stack_array/ut/tests_ut.cpp170
-rw-r--r--library/cpp/containers/stack_array/ut/ya.make16
-rw-r--r--library/cpp/containers/stack_array/ya.make20
7 files changed, 171 insertions, 171 deletions
diff --git a/library/cpp/containers/stack_array/range_ops.cpp b/library/cpp/containers/stack_array/range_ops.cpp
index ea47fe6777..f1b5e3af0d 100644
--- a/library/cpp/containers/stack_array/range_ops.cpp
+++ b/library/cpp/containers/stack_array/range_ops.cpp
@@ -1 +1 @@
-#include "range_ops.h"
+#include "range_ops.h"
diff --git a/library/cpp/containers/stack_array/range_ops.h b/library/cpp/containers/stack_array/range_ops.h
index dfb95ab401..1d40341aa1 100644
--- a/library/cpp/containers/stack_array/range_ops.h
+++ b/library/cpp/containers/stack_array/range_ops.h
@@ -1,52 +1,52 @@
-#pragma once
-
-#include <util/generic/typetraits.h>
-
-#include <new>
-
-namespace NRangeOps {
- template <class T, bool isTrivial>
- struct TRangeOpsBase {
+#pragma once
+
+#include <util/generic/typetraits.h>
+
+#include <new>
+
+namespace NRangeOps {
+ template <class T, bool isTrivial>
+ struct TRangeOpsBase {
static inline void DestroyRange(T* b, T* e) noexcept {
- while (e > b) {
- (--e)->~T();
- }
- }
-
- static inline void InitializeRange(T* b, T* e) {
- T* c = b;
-
- try {
- for (; c < e; ++c) {
- new (c) T();
- }
- } catch (...) {
- DestroyRange(b, c);
-
- throw;
- }
- }
- };
-
- template <class T>
- struct TRangeOpsBase<T, true> {
+ while (e > b) {
+ (--e)->~T();
+ }
+ }
+
+ static inline void InitializeRange(T* b, T* e) {
+ T* c = b;
+
+ try {
+ for (; c < e; ++c) {
+ new (c) T();
+ }
+ } catch (...) {
+ DestroyRange(b, c);
+
+ throw;
+ }
+ }
+ };
+
+ template <class T>
+ struct TRangeOpsBase<T, true> {
static inline void DestroyRange(T*, T*) noexcept {
- }
-
+ }
+
static inline void InitializeRange(T*, T*) noexcept {
- }
- };
-
- template <class T>
- using TRangeOps = TRangeOpsBase<T, TTypeTraits<T>::IsPod>;
-
- template <class T>
+ }
+ };
+
+ template <class T>
+ using TRangeOps = TRangeOpsBase<T, TTypeTraits<T>::IsPod>;
+
+ template <class T>
static inline void DestroyRange(T* b, T* e) noexcept {
- TRangeOps<T>::DestroyRange(b, e);
- }
-
- template <class T>
- static inline void InitializeRange(T* b, T* e) {
- TRangeOps<T>::InitializeRange(b, e);
- }
-}
+ TRangeOps<T>::DestroyRange(b, e);
+ }
+
+ template <class T>
+ static inline void InitializeRange(T* b, T* e) {
+ TRangeOps<T>::InitializeRange(b, e);
+ }
+}
diff --git a/library/cpp/containers/stack_array/stack_array.cpp b/library/cpp/containers/stack_array/stack_array.cpp
index d579328128..68e8b097ba 100644
--- a/library/cpp/containers/stack_array/stack_array.cpp
+++ b/library/cpp/containers/stack_array/stack_array.cpp
@@ -1 +1 @@
-#include "stack_array.h"
+#include "stack_array.h"
diff --git a/library/cpp/containers/stack_array/stack_array.h b/library/cpp/containers/stack_array/stack_array.h
index 105189de06..28e49bfc3c 100644
--- a/library/cpp/containers/stack_array/stack_array.h
+++ b/library/cpp/containers/stack_array/stack_array.h
@@ -1,11 +1,11 @@
-#pragma once
-
-#include "range_ops.h"
-
+#pragma once
+
+#include "range_ops.h"
+
#include <util/generic/array_ref.h>
#include <util/system/defaults.h> /* For alloca. */
-
-namespace NStackArray {
+
+namespace NStackArray {
/**
* A stack-allocated array. Should be used instead of � variable length
* arrays that are not part of C++ standard.
@@ -21,20 +21,20 @@ namespace NStackArray {
*
* Note that it is generally a *VERY BAD* idea to use this in inline methods
* as those might be called from a loop, and then stack overflow is in the cards.
- */
- template <class T>
+ */
+ template <class T>
class TStackArray: public TArrayRef<T> {
- public:
- inline TStackArray(void* data, size_t len)
+ public:
+ inline TStackArray(void* data, size_t len)
: TArrayRef<T>((T*)data, len)
- {
+ {
NRangeOps::InitializeRange(this->begin(), this->end());
- }
-
+ }
+
inline ~TStackArray() {
NRangeOps::DestroyRange(this->begin(), this->end());
- }
- };
-}
-
-#define ALLOC_ON_STACK(type, n) alloca(sizeof(type) * (n)), (n)
+ }
+ };
+}
+
+#define ALLOC_ON_STACK(type, n) alloca(sizeof(type) * (n)), (n)
diff --git a/library/cpp/containers/stack_array/ut/tests_ut.cpp b/library/cpp/containers/stack_array/ut/tests_ut.cpp
index d0c4bfe8c0..3e96384f0e 100644
--- a/library/cpp/containers/stack_array/ut/tests_ut.cpp
+++ b/library/cpp/containers/stack_array/ut/tests_ut.cpp
@@ -1,94 +1,94 @@
#include <library/cpp/containers/stack_array/stack_array.h>
#include <library/cpp/testing/unittest/registar.h>
-
+
Y_UNIT_TEST_SUITE(TestStackArray) {
- using namespace NStackArray;
-
- static inline void* FillWithTrash(void* d, size_t l) {
- memset(d, 0xCC, l);
-
- return d;
- }
-
-#define ALLOC(type, len) FillWithTrash(alloca(sizeof(type) * len), sizeof(type) * len), len
-
+ using namespace NStackArray;
+
+ static inline void* FillWithTrash(void* d, size_t l) {
+ memset(d, 0xCC, l);
+
+ return d;
+ }
+
+#define ALLOC(type, len) FillWithTrash(alloca(sizeof(type) * len), sizeof(type) * len), len
+
Y_UNIT_TEST(Test1) {
- TStackArray<ui32> s(ALLOC(ui32, 10));
-
+ TStackArray<ui32> s(ALLOC(ui32, 10));
+
UNIT_ASSERT_VALUES_EQUAL(s.size(), 10);
-
+
for (size_t i = 0; i < s.size(); ++i) {
- UNIT_ASSERT_VALUES_EQUAL(s[i], 0xCCCCCCCC);
- }
-
- for (auto&& x : s) {
- UNIT_ASSERT_VALUES_EQUAL(x, 0xCCCCCCCC);
- }
-
+ UNIT_ASSERT_VALUES_EQUAL(s[i], 0xCCCCCCCC);
+ }
+
+ for (auto&& x : s) {
+ UNIT_ASSERT_VALUES_EQUAL(x, 0xCCCCCCCC);
+ }
+
for (size_t i = 0; i < s.size(); ++i) {
- s[i] = i;
- }
-
- size_t ss = 0;
-
- for (auto&& x : s) {
- ss += x;
- }
-
- UNIT_ASSERT_VALUES_EQUAL(ss, 45);
- }
-
- static int N1 = 0;
-
- struct TX1 {
- inline TX1() {
- ++N1;
- }
-
- inline ~TX1() {
- --N1;
- }
- };
-
+ s[i] = i;
+ }
+
+ size_t ss = 0;
+
+ for (auto&& x : s) {
+ ss += x;
+ }
+
+ UNIT_ASSERT_VALUES_EQUAL(ss, 45);
+ }
+
+ static int N1 = 0;
+
+ struct TX1 {
+ inline TX1() {
+ ++N1;
+ }
+
+ inline ~TX1() {
+ --N1;
+ }
+ };
+
Y_UNIT_TEST(Test2) {
- {
- TStackArray<TX1> s(ALLOC(TX1, 10));
-
- UNIT_ASSERT_VALUES_EQUAL(N1, 10);
- }
-
- UNIT_ASSERT_VALUES_EQUAL(N1, 0);
- }
-
- static int N2 = 0;
- static int N3 = 0;
-
- struct TX2 {
- inline TX2() {
- if (N2 >= 5) {
- ythrow yexception() << "ups";
- }
-
- ++N3;
- ++N2;
- }
-
- inline ~TX2() {
- --N2;
- }
- };
-
+ {
+ TStackArray<TX1> s(ALLOC(TX1, 10));
+
+ UNIT_ASSERT_VALUES_EQUAL(N1, 10);
+ }
+
+ UNIT_ASSERT_VALUES_EQUAL(N1, 0);
+ }
+
+ static int N2 = 0;
+ static int N3 = 0;
+
+ struct TX2 {
+ inline TX2() {
+ if (N2 >= 5) {
+ ythrow yexception() << "ups";
+ }
+
+ ++N3;
+ ++N2;
+ }
+
+ inline ~TX2() {
+ --N2;
+ }
+ };
+
Y_UNIT_TEST(Test3) {
- bool haveException = false;
-
- try {
- TStackArray<TX2> s(ALLOC_ON_STACK(TX2, 10));
- } catch (...) {
- haveException = true;
- }
-
- UNIT_ASSERT(haveException);
- UNIT_ASSERT_VALUES_EQUAL(N2, 0);
- UNIT_ASSERT_VALUES_EQUAL(N3, 5);
- }
-}
+ bool haveException = false;
+
+ try {
+ TStackArray<TX2> s(ALLOC_ON_STACK(TX2, 10));
+ } catch (...) {
+ haveException = true;
+ }
+
+ UNIT_ASSERT(haveException);
+ UNIT_ASSERT_VALUES_EQUAL(N2, 0);
+ UNIT_ASSERT_VALUES_EQUAL(N3, 5);
+ }
+}
diff --git a/library/cpp/containers/stack_array/ut/ya.make b/library/cpp/containers/stack_array/ut/ya.make
index f224ff2942..7db7340073 100644
--- a/library/cpp/containers/stack_array/ut/ya.make
+++ b/library/cpp/containers/stack_array/ut/ya.make
@@ -1,9 +1,9 @@
UNITTEST_FOR(library/cpp/containers/stack_array)
-
-OWNER(pg)
-
-SRCS(
- tests_ut.cpp
-)
-
-END()
+
+OWNER(pg)
+
+SRCS(
+ tests_ut.cpp
+)
+
+END()
diff --git a/library/cpp/containers/stack_array/ya.make b/library/cpp/containers/stack_array/ya.make
index ad84393f02..9bc0afc66c 100644
--- a/library/cpp/containers/stack_array/ya.make
+++ b/library/cpp/containers/stack_array/ya.make
@@ -1,10 +1,10 @@
-LIBRARY()
-
-OWNER(pg)
-
-SRCS(
- range_ops.cpp
- stack_array.cpp
-)
-
-END()
+LIBRARY()
+
+OWNER(pg)
+
+SRCS(
+ range_ops.cpp
+ stack_array.cpp
+)
+
+END()