Skip to content

Commit 4dea813

Browse files
committed
FIX | some bugs
1 parent 50e8ee8 commit 4dea813

4 files changed

Lines changed: 27 additions & 10 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ if (MANAPIHTTP_BUILD_METHOD STREQUAL "conan")
10611061

10621062
if (MANAPIHTTP_ZSTD_DEPENDENCY)
10631063
target_link_libraries(${PROJECT_NAME} PUBLIC ${zstd_COMPONENT_NAMES})
1064-
endif ()
1064+
endqif ()
10651065

10661066
if (MANAPIHTTP_NGHTTP2_DEPENDENCY)
10671067
target_link_libraries(${PROJECT_NAME} PUBLIC libnghttp2::libnghttp2)

include/cache/ManapiLRU.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,17 @@ namespace manapi {
3636
}
3737

3838
void put (const K &key, const V &value, std::size_t weight) {
39+
iput(key, V(value), weight);
40+
}
41+
42+
void put (const K &key, V &&value, std::size_t weight) {
43+
iput(key, std::forward<V>(value), weight);
44+
}
45+
46+
void iput (const K &key, V &&value, std::size_t weight) {
3947
auto it = this->m_items.find(key);
4048
if (it == this->m_items.end()) {
41-
this->m_list.push_front(key_value_pair_t (key, value));
49+
this->m_list.push_front(key_value_pair_t (key, std::forward<V>(value)));
4250
try {
4351
item_t item (this->m_list.begin(), weight);
4452
this->m_items.insert({key, std::move(item)});
@@ -49,7 +57,7 @@ namespace manapi {
4957
}
5058
}
5159
else {
52-
it->second.item->second = value; // malloc can be only here
60+
it->second.item->second = std::forward<V>(value); // malloc can be only here
5361

5462
std::unique_ptr<chain_item<key_value_pair_t>> un;
5563
this->m_used -= it->second.weight;

include/cache/ManapiTL.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@ namespace manapi {
2222
}
2323

2424
void put (const K &key, const V &value, std::chrono::milliseconds duration) {
25+
this->iput(K(key), V(value), duration);
26+
}
27+
28+
void put (const K &key, V &&value, std::chrono::milliseconds duration) {
29+
this->iput(key, std::forward<V>(value), duration);
30+
}
31+
32+
void iput (const K &key, V &&value, std::chrono::milliseconds duration) {
2533
this->cleanup();
26-
auto id = std::make_pair(std::chrono::steady_clock::now() + duration, value);
34+
auto id = std::make_pair(std::chrono::steady_clock::now() + duration, std::forward<decltype(value)>(value));
2735
auto it = this->m_data.insert({key, id});
2836
if (!it.second) {
2937
this->m_sorted.erase(std::make_pair(it.first->second.first, it.first->first));

include/std/ManapiScopePtr.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace manapi {
1010
bool own;
1111

1212
public:
13-
explicit scope_ptr(T* p = nullptr, bool ownership = true)
13+
scope_ptr(T* p = nullptr, bool ownership = true)
1414
: ptr(p), own(ownership) {}
1515

1616
~scope_ptr() {
@@ -31,13 +31,14 @@ namespace manapi {
3131

3232
scope_ptr& operator=(scope_ptr&& other) MANAPIHTTP_NOEXCEPT {
3333
if (this != &other) {
34-
if (this->own) {
35-
delete this->ptr;
36-
}
37-
this->ptr = other.ptr;
38-
this->own = other.own;
34+
auto ptrn = other.ptr;
35+
auto ownn = other.own;
3936
other.ptr = nullptr;
4037
other.own = false;
38+
if (this->own)
39+
delete this->ptr;
40+
this->ptr = ptrn;
41+
this->own = ownn;
4142
}
4243
return *this;
4344
}

0 commit comments

Comments
 (0)