Skip to content

Commit 9206e67

Browse files
committed
Refactor naming convention in new and delete functions.
1 parent a0732c8 commit 9206e67

File tree

6 files changed

+38
-38
lines changed

6 files changed

+38
-38
lines changed

benchmark/benchmark_new.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ struct policy_cpp_new {
106106
template <std::size_t AllocSize>
107107
struct policy_pmr_new {
108108
static void *allocate() noexcept {
109-
return pmr::new$<std::array<char, AllocSize>>();
109+
return pmr::$new<std::array<char, AllocSize>>();
110110
}
111111

112112
static void deallocate(void *p) noexcept {
113-
pmr::delete$(static_cast<std::array<char, AllocSize> *>(p));
113+
pmr::$delete(static_cast<std::array<char, AllocSize> *>(p));
114114
}
115115
};
116116

include/libimp/detect_plat.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@
211211
defined(__EXCEPTIONS) || defined(_CPPUNWIND)
212212
# define LIBIMP_TRY try
213213
# define LIBIMP_CATCH(...) catch (__VA_ARGS__)
214-
# define LIBIMP_THROW($exception, ...) throw $exception
214+
# define LIBIMP_THROW($EXCEPTION, ...) throw $EXCEPTION
215215
#else
216216
# define LIBIMP_TRY if (true)
217217
# define LIBIMP_CATCH(...) else if (false)
218-
# define LIBIMP_THROW($exception, ...) return __VA_ARGS__
218+
# define LIBIMP_THROW($EXCEPTION, ...) return __VA_ARGS__
219219
#endif

include/libimp/scope_exit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct scope_exit_helper {
7373

7474
} // namespace detail
7575

76-
#define LIBIMP_SCOPE_EXIT($val) \
77-
LIBIMP_UNUSED auto $val = ::LIBIMP::detail::scope_exit_helper{}
76+
#define LIBIMP_SCOPE_EXIT($VAL) \
77+
LIBIMP_UNUSED auto $VAL = ::LIBIMP::detail::scope_exit_helper{}
7878

7979
LIBIMP_NAMESPACE_END_

include/libpmr/new.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,17 @@ auto *get_regular_resource() noexcept {
144144
/// \brief Creates an object based on the specified type and parameters with block pool resource.
145145
/// \note This function is thread-safe.
146146
template <typename T, typename... A>
147-
T *new$(A &&... args) noexcept {
147+
T *$new(A &&... args) noexcept {
148148
auto *res = get_regular_resource<T>();
149149
if (res == nullptr) return nullptr;
150150
return ::LIBIMP::construct<T>(res->allocate(sizeof(T), alignof(T)), std::forward<A>(args)...);
151151
}
152152

153-
/// \brief Destroys object previously allocated by the `new$` and releases obtained memory area.
154-
/// \note This function is thread-safe. If the pointer type passed in is different from `new$`,
153+
/// \brief Destroys object previously allocated by the `$new` and releases obtained memory area.
154+
/// \note This function is thread-safe. If the pointer type passed in is different from `$new`,
155155
/// additional performance penalties may be incurred.
156156
template <typename T>
157-
void delete$(T *p) noexcept {
157+
void $delete(T *p) noexcept {
158158
if (p == nullptr) return;
159159
::LIBIMP::destroy(p);
160160
auto *res = get_regular_resource<T>();

src/libimp/codecvt.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,12 @@ auto cvt_cstr_utf(T const *src, std::size_t slen, U *des, std::size_t dlen) noex
324324

325325
} // namespace
326326

327-
#define LIBIMP_DEF_CVT_CSTR_($char_t, $char_u) \
327+
#define LIBIMP_DEF_CVT_CSTR_($CHAR_T, $CHAR_U) \
328328
template <> \
329-
std::size_t cvt_cstr($char_t const *src, std::size_t slen, $char_u *des, std::size_t dlen) noexcept { \
329+
std::size_t cvt_cstr($CHAR_T const *src, std::size_t slen, $CHAR_U *des, std::size_t dlen) noexcept { \
330330
return cvt_cstr_utf(src, slen, des, dlen); \
331331
}
332-
// #define LIBIMP_DEF_CVT_CSTR_($char_t, $char_u)
332+
// #define LIBIMP_DEF_CVT_CSTR_($CHAR_T, $CHAR_U)
333333

334334
LIBIMP_DEF_CVT_CSTR_(char , char)
335335
LIBIMP_DEF_CVT_CSTR_(char , char16_t)

test/pmr/test_pmr_new.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ TEST(pmr_new, regular_sizeof) {
2222
ASSERT_EQ((pmr::regular_sizeof<std::array<char, 100000>>()), (std::numeric_limits<std::size_t>::max)());
2323
}
2424

25-
TEST(pmr_new, new$) {
26-
auto p = pmr::new$<int>();
25+
TEST(pmr_new, $new) {
26+
auto p = pmr::$new<int>();
2727
ASSERT_NE(p, nullptr);
2828
*p = -1;
2929
ASSERT_EQ(*p, -1);
30-
pmr::delete$(p);
30+
pmr::$delete(p);
3131
}
3232

33-
TEST(pmr_new, new$value) {
34-
auto p = pmr::new$<int>((std::numeric_limits<int>::max)());
33+
TEST(pmr_new, $new_value) {
34+
auto p = pmr::$new<int>((std::numeric_limits<int>::max)());
3535
ASSERT_NE(p, nullptr);
3636
ASSERT_EQ(*p, (std::numeric_limits<int>::max)());
37-
pmr::delete$(p);
37+
pmr::$delete(p);
3838
}
3939

4040
namespace {
@@ -44,21 +44,21 @@ void test_new$array() {
4444
std::array<void *, Pts> pts;
4545
using T = std::array<char, N>;
4646
for (int i = 0; i < (int)pts.size(); ++i) {
47-
auto p = pmr::new$<T>();
47+
auto p = pmr::$new<T>();
4848
pts[i] = p;
4949
std::memset(p, i, sizeof(T));
5050
}
5151
for (int i = 0; i < (int)pts.size(); ++i) {
5252
T tmp;
5353
std::memset(&tmp, i, sizeof(T));
5454
ASSERT_EQ(std::memcmp(pts[i], &tmp, sizeof(T)), 0);
55-
pmr::delete$(static_cast<T *>(pts[i]));
55+
pmr::$delete(static_cast<T *>(pts[i]));
5656
}
5757
}
5858

5959
} // namespace
6060

61-
TEST(pmr_new, new$array) {
61+
TEST(pmr_new, $new_array) {
6262
test_new$array<1000, 10>();
6363
test_new$array<1000, 100>();
6464
test_new$array<1000, 1000>();
@@ -103,39 +103,39 @@ class Derived64K : public Derived {
103103

104104
} // namespace
105105

106-
TEST(pmr_new, delete$poly) {
107-
Base *p = pmr::new$<Derived>(-1);
106+
TEST(pmr_new, $delete_poly) {
107+
Base *p = pmr::$new<Derived>(-1);
108108
ASSERT_NE(p, nullptr);
109109
ASSERT_EQ(p->get(), -1);
110110
ASSERT_EQ(construct_count__, -1);
111-
pmr::delete$(p);
111+
pmr::$delete(p);
112112
ASSERT_EQ(construct_count__, 0);
113113

114-
ASSERT_EQ(p, pmr::new$<Derived>((std::numeric_limits<int>::max)()));
114+
ASSERT_EQ(p, pmr::$new<Derived>((std::numeric_limits<int>::max)()));
115115
ASSERT_EQ(p->get(), (std::numeric_limits<int>::max)());
116116
ASSERT_EQ(construct_count__, (std::numeric_limits<int>::max)());
117-
pmr::delete$(p);
117+
pmr::$delete(p);
118118
ASSERT_EQ(construct_count__, 0);
119119
}
120120

121-
TEST(pmr_new, delete$poly64k) {
122-
Base *p = pmr::new$<Derived64K>(-1);
121+
TEST(pmr_new, $delete_poly64k) {
122+
Base *p = pmr::$new<Derived64K>(-1);
123123
ASSERT_NE(p, nullptr);
124124
ASSERT_EQ(p->get(), -1);
125125
ASSERT_EQ(construct_count__, -1);
126-
pmr::delete$(p);
126+
pmr::$delete(p);
127127
ASSERT_EQ(construct_count__, 0);
128128

129-
Base *q = pmr::new$<Derived64K>((std::numeric_limits<int>::max)());
129+
Base *q = pmr::$new<Derived64K>((std::numeric_limits<int>::max)());
130130
ASSERT_EQ(q->get(), (std::numeric_limits<int>::max)());
131131
ASSERT_EQ(construct_count__, (std::numeric_limits<int>::max)());
132-
pmr::delete$(q);
132+
pmr::$delete(q);
133133
ASSERT_EQ(construct_count__, 0);
134134
}
135135

136-
TEST(pmr_new, delete$null) {
136+
TEST(pmr_new, $delete_null) {
137137
Base *p = nullptr;
138-
pmr::delete$(p);
138+
pmr::$delete(p);
139139
SUCCEED();
140140
}
141141

@@ -144,21 +144,21 @@ TEST(pmr_new, multi_thread) {
144144
for (auto &t : threads) {
145145
t = std::thread([] {
146146
for (int i = 0; i < 10000; ++i) {
147-
auto p = pmr::new$<int>();
147+
auto p = pmr::$new<int>();
148148
*p = i;
149-
pmr::delete$(p);
149+
pmr::$delete(p);
150150
}
151151
std::array<void *, 10000> pts;
152152
for (int i = 0; i < 10000; ++i) {
153-
auto p = pmr::new$<std::array<char, 10>>();
153+
auto p = pmr::$new<std::array<char, 10>>();
154154
pts[i] = p;
155155
std::memset(p, i, sizeof(std::array<char, 10>));
156156
}
157157
for (int i = 0; i < 10000; ++i) {
158158
std::array<char, 10> tmp;
159159
std::memset(&tmp, i, sizeof(std::array<char, 10>));
160160
ASSERT_EQ(std::memcmp(pts[i], &tmp, sizeof(std::array<char, 10>)), 0);
161-
pmr::delete$(static_cast<std::array<char, 10> *>(pts[i]));
161+
pmr::$delete(static_cast<std::array<char, 10> *>(pts[i]));
162162
}
163163
});
164164
}

0 commit comments

Comments
 (0)