Merge pull request #431 from oatpp/Remove_LinkedList

Replaced oatpp::core::collection::LinkedList by std::list
This commit is contained in:
Leonid Stryzhevskyi 2021-05-20 01:06:06 +03:00 committed by GitHub
commit e70d4924de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 46 additions and 519 deletions

View File

@ -64,8 +64,6 @@ add_library(oatpp
oatpp/core/base/memory/ObjectPool.cpp oatpp/core/base/memory/ObjectPool.cpp
oatpp/core/base/memory/ObjectPool.hpp oatpp/core/base/memory/ObjectPool.hpp
oatpp/core/collection/FastQueue.hpp oatpp/core/collection/FastQueue.hpp
oatpp/core/collection/LinkedList.hpp
oatpp/core/concurrency/SpinLock.cpp oatpp/core/concurrency/SpinLock.cpp
oatpp/core/concurrency/SpinLock.hpp oatpp/core/concurrency/SpinLock.hpp
oatpp/core/concurrency/Thread.cpp oatpp/core/concurrency/Thread.cpp

View File

@ -31,8 +31,6 @@
#include "oatpp/core/concurrency/SpinLock.hpp" #include "oatpp/core/concurrency/SpinLock.hpp"
#include "oatpp/core/concurrency/Thread.hpp" #include "oatpp/core/concurrency/Thread.hpp"
#include "oatpp/core/collection/LinkedList.hpp"
#include <tuple> #include <tuple>
#include <mutex> #include <mutex>
#include <condition_variable> #include <condition_variable>

View File

@ -26,7 +26,6 @@
#define oatpp_async_worker_IOWorker_hpp #define oatpp_async_worker_IOWorker_hpp
#include "./Worker.hpp" #include "./Worker.hpp"
#include "oatpp/core/collection/LinkedList.hpp"
#include "oatpp/core/concurrency/SpinLock.hpp" #include "oatpp/core/concurrency/SpinLock.hpp"
#include <thread> #include <thread>

View File

@ -26,7 +26,6 @@
#define oatpp_async_worker_TimerWorker_hpp #define oatpp_async_worker_TimerWorker_hpp
#include "./Worker.hpp" #include "./Worker.hpp"
#include "oatpp/core/collection/LinkedList.hpp"
#include "oatpp/core/concurrency/SpinLock.hpp" #include "oatpp/core/concurrency/SpinLock.hpp"
#include <thread> #include <thread>

View File

@ -1,281 +0,0 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#ifndef oatpp_collection_LinkedList_hpp
#define oatpp_collection_LinkedList_hpp
#include "oatpp/core/base/memory/ObjectPool.hpp"
#include "oatpp/core/base/Countable.hpp"
#include "oatpp/core/base/Environment.hpp"
namespace oatpp { namespace collection {
template<class T>
class LinkedList : public base::Countable {
public:
OBJECT_POOL(LinkedList_Pool, LinkedList, 32)
SHARED_OBJECT_POOL(Shared_LinkedList_Pool, LinkedList, 32)
public:
class LinkedListNode {
friend LinkedList;
friend oatpp::base::memory::MemoryPool;
public:
OBJECT_POOL_THREAD_LOCAL(LinkedList_Node_Pool, LinkedListNode, 32)
private:
T data;
LinkedListNode* next;
protected:
LinkedListNode(const T& nodeData, LinkedListNode* nextNode)
: data(nodeData)
, next(nextNode)
{}
~LinkedListNode(){
}
public:
const T& getData(){
return data;
}
LinkedListNode* getNext(){
return next;
}
};
private:
LinkedListNode* m_first;
LinkedListNode* m_last;
v_int32 m_count;
oatpp::base::memory::MemoryPool& m_itemMemoryPool;
LinkedListNode* createNode(const T& data, LinkedListNode* next){
return new (m_itemMemoryPool.obtain()) LinkedListNode(data, next);
}
void destroyNode(LinkedListNode* node){
node->~LinkedListNode();
oatpp::base::memory::MemoryPool::free(node);
}
public:
LinkedList()
: m_first(nullptr)
, m_last(nullptr)
, m_count(0)
, m_itemMemoryPool(LinkedListNode::LinkedList_Node_Pool::getPool())
{}
public:
static std::shared_ptr<LinkedList> createShared(){
return Shared_LinkedList_Pool::allocateShared();
}
static std::shared_ptr<LinkedList> copy(LinkedList<T>* other){
auto result = createShared();
auto curr = other->m_first;
while(curr != nullptr){
result->pushBack(curr->data);
curr = curr->next;
}
return result;
}
virtual ~LinkedList() {
clear();
}
void pushFront(const T& data){
if(m_first == nullptr){
LinkedListNode* newNode = createNode(data, nullptr);
m_first = newNode;
m_last = newNode;
}else{
LinkedListNode* newNode = createNode(data, m_first);
m_first = newNode;
}
m_count++;
}
void pushBack(const T& data){
LinkedListNode* newNode = createNode(data, nullptr);
if(m_last == nullptr){
m_first = newNode;
m_last = newNode;
}else{
m_last->next = newNode;
m_last = newNode;
}
m_count++;
}
void pushBackAll(const std::shared_ptr<LinkedList>& list){
auto curr = list->getFirstNode();
while(curr != nullptr) {
pushBack(curr->getData());
curr = curr->getNext();
}
}
void insertAfterNode(const T& data, LinkedListNode* currentNode){
LinkedListNode* node = createNode(data, currentNode->next);
currentNode->next = node;
if(currentNode == m_last){
m_last = node;
}
m_count++;
}
T popFront(){
if(m_first != nullptr){
LinkedListNode* node = m_first;
m_first = m_first->next;
if(m_first == nullptr){
m_last = nullptr;
}
m_count --;
T result = node->data;
destroyNode(node);
return result;
}
throw std::runtime_error("[oatpp::collection::LinkedList::popFront()]: index out of bounds");
}
const T& getFirst() const{
return m_first->data;
}
const T& getLast() const{
return m_last->data;
}
const T& get(v_int32 index) const{
LinkedListNode* node = getNode(index);
if(node != nullptr){
return node->data;
}
throw std::runtime_error("[oatpp::collection::LinkedList::get(index)]: index out of bounds");
}
LinkedListNode* getNode(v_int32 index) const {
if(index >= m_count){
return nullptr;
}
v_int32 i = 0;
LinkedListNode* curr = m_first;
while(curr != nullptr){
if(i == index){
return curr;
}
curr = curr->next;
i++;
}
return nullptr;
}
LinkedListNode* getFirstNode() const {
return m_first;
}
v_int32 count() const{
return m_count;
}
/**
* for each item call a function
*
* list->forEachNode([](auto item){
* // your code here
* });
*/
template<typename F>
void forEach(const F& lambda) const {
auto curr = m_first;
while(curr != nullptr) {
lambda(curr->data);
curr = curr->next;
}
}
/**
* for each node call a function
*
* list->forEachNode([](auto node){
* // your code here
* });
*/
template<typename F>
void forEachNode(const F& lambda) const {
auto curr = m_first;
while(curr != nullptr) {
lambda(curr);
curr = curr->next;
}
}
void clear(){
LinkedListNode* curr = m_first;
while(curr != nullptr){
LinkedListNode* next = curr->next;
destroyNode(curr);
curr = next;
}
m_first = nullptr;
m_last = nullptr;
m_count = 0;
}
};
}}
#endif /* oatpp_collection_LinkedList_hpp */

View File

@ -27,8 +27,6 @@
#include "./Type.hpp" #include "./Type.hpp"
#include "oatpp/core/collection/LinkedList.hpp"
#include "oatpp/core/base/memory/ObjectPool.hpp" #include "oatpp/core/base/memory/ObjectPool.hpp"
#include "oatpp/core/base/Countable.hpp" #include "oatpp/core/base/Countable.hpp"

View File

@ -303,15 +303,13 @@ oatpp::async::CoroutineStarter ChunkedBuffer::flushToStreamAsync(const std::shar
} }
std::shared_ptr<ChunkedBuffer::Chunks> ChunkedBuffer::getChunks() { std::shared_ptr<ChunkedBuffer::Chunks> ChunkedBuffer::getChunks() {
auto chunks = Chunks::createShared(); auto chunks = std::make_shared<Chunks>();
auto curr = m_firstEntry; auto curr = m_firstEntry;
v_int32 count = 0; v_int32 count = 0;
while (curr != nullptr) { while (curr != nullptr) {
if(curr->next != nullptr){ chunks->push_back(Chunk::createShared(curr->chunk, curr->next
chunks->pushBack(Chunk::createShared(curr->chunk, CHUNK_ENTRY_SIZE)); ? CHUNK_ENTRY_SIZE
} else { : m_size - CHUNK_ENTRY_SIZE * count));
chunks->pushBack(Chunk::createShared(curr->chunk, m_size - CHUNK_ENTRY_SIZE * count));
}
++count; ++count;
curr = curr->next; curr = curr->next;
} }

View File

@ -25,9 +25,10 @@
#ifndef oatpp_data_stream_ChunkedBuffer_hpp #ifndef oatpp_data_stream_ChunkedBuffer_hpp
#define oatpp_data_stream_ChunkedBuffer_hpp #define oatpp_data_stream_ChunkedBuffer_hpp
#include <list>
#include "Stream.hpp" #include "Stream.hpp"
#include "oatpp/core/collection/LinkedList.hpp"
#include "oatpp/core/async/Coroutine.hpp" #include "oatpp/core/async/Coroutine.hpp"
namespace oatpp { namespace data{ namespace stream { namespace oatpp { namespace data{ namespace stream {
@ -99,7 +100,7 @@ public:
}; };
public: public:
typedef oatpp::collection::LinkedList<std::shared_ptr<Chunk>> Chunks; typedef std::list<std::shared_ptr<Chunk>> Chunks;
private: private:
v_buff_size m_size; v_buff_size m_size;

View File

@ -25,7 +25,6 @@
#ifndef oatpp_parser_Caret_hpp #ifndef oatpp_parser_Caret_hpp
#define oatpp_parser_Caret_hpp #define oatpp_parser_Caret_hpp
#include "oatpp/core/collection/LinkedList.hpp"
#include "oatpp/core/Types.hpp" #include "oatpp/core/Types.hpp"
namespace oatpp { namespace parser { namespace oatpp { namespace parser {

View File

@ -184,7 +184,7 @@ std::shared_ptr<Interface::ConnectionSubmission> Interface::connect() {
auto submission = std::make_shared<ConnectionSubmission>(true); auto submission = std::make_shared<ConnectionSubmission>(true);
{ {
std::lock_guard<std::mutex> lock(m_mutex); std::lock_guard<std::mutex> lock(m_mutex);
m_submissions.pushBack(submission); m_submissions.push_back(submission);
} }
m_condition.notify_one(); m_condition.notify_one();
return submission; return submission;
@ -199,7 +199,7 @@ std::shared_ptr<Interface::ConnectionSubmission> Interface::connectNonBlocking()
std::unique_lock<std::mutex> lock(m_mutex, std::try_to_lock); std::unique_lock<std::mutex> lock(m_mutex, std::try_to_lock);
if (lock.owns_lock()) { if (lock.owns_lock()) {
submission = std::make_shared<ConnectionSubmission>(true); submission = std::make_shared<ConnectionSubmission>(true);
m_submissions.pushBack(submission); m_submissions.push_back(submission);
} }
} }
if (submission) { if (submission) {
@ -212,19 +212,23 @@ std::shared_ptr<Interface::ConnectionSubmission> Interface::connectNonBlocking()
std::shared_ptr<Socket> Interface::accept(const bool& waitingHandle) { std::shared_ptr<Socket> Interface::accept(const bool& waitingHandle) {
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
while (waitingHandle && m_submissions.getFirstNode() == nullptr) { while (waitingHandle && m_submissions.empty()) {
m_condition.wait(lock); m_condition.wait(lock);
} }
if(!waitingHandle) { if(!waitingHandle) {
return nullptr; return nullptr;
} }
return acceptSubmission(m_submissions.popFront()); const auto submission = m_submissions.front();
m_submissions.pop_front();
return acceptSubmission(submission);
} }
std::shared_ptr<Socket> Interface::acceptNonBlocking() { std::shared_ptr<Socket> Interface::acceptNonBlocking() {
std::unique_lock<std::mutex> lock(m_mutex, std::try_to_lock); std::unique_lock<std::mutex> lock(m_mutex, std::try_to_lock);
if(lock.owns_lock() && m_submissions.getFirstNode() != nullptr) { if(lock.owns_lock() && !m_submissions.empty()) {
return acceptSubmission(m_submissions.popFront()); const auto submission = m_submissions.front();
m_submissions.pop_front();
return acceptSubmission(submission);
} }
return nullptr; return nullptr;
} }
@ -233,14 +237,9 @@ void Interface::dropAllConnection() {
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
auto curr = m_submissions.getFirstNode(); for (const auto& submission : m_submissions) {
while(curr != nullptr) {
auto submission = curr->getData();
submission->invalidate(); submission->invalidate();
curr = curr->getNext();
} }
m_submissions.clear(); m_submissions.clear();
} }

View File

@ -27,8 +27,7 @@
#include "./Socket.hpp" #include "./Socket.hpp"
#include "oatpp/core/collection/LinkedList.hpp" #include <list>
#include <unordered_map> #include <unordered_map>
namespace oatpp { namespace network { namespace virtual_ { namespace oatpp { namespace network { namespace virtual_ {
@ -116,7 +115,7 @@ private:
std::mutex m_listenerMutex; std::mutex m_listenerMutex;
std::mutex m_mutex; std::mutex m_mutex;
std::condition_variable m_condition; std::condition_variable m_condition;
oatpp::collection::LinkedList<std::shared_ptr<ConnectionSubmission>> m_submissions; std::list<std::shared_ptr<ConnectionSubmission>> m_submissions;
private: private:
Interface(const oatpp::String& name); Interface(const oatpp::String& name);

View File

@ -28,12 +28,9 @@
namespace oatpp { namespace web { namespace server { namespace api { namespace oatpp { namespace web { namespace server { namespace api {
void ApiController::addEndpointsToRouter(const std::shared_ptr<Router>& router){ void ApiController::addEndpointsToRouter(const std::shared_ptr<Router>& router){
auto node = m_endpoints->getFirstNode(); for (const auto& endpoint : *m_endpoints) {
while (node != nullptr) {
auto endpoint = node->getData();
router->route(endpoint->info()->method, endpoint->info()->path, endpoint->handler); router->route(endpoint->info()->method, endpoint->info()->path, endpoint->handler);
node = node->getNext(); };
}
} }
std::shared_ptr<ApiController::Endpoints> ApiController::getEndpoints() { std::shared_ptr<ApiController::Endpoints> ApiController::getEndpoints() {

View File

@ -36,9 +36,9 @@
#include "oatpp/web/protocol/http/outgoing/Request.hpp" #include "oatpp/web/protocol/http/outgoing/Request.hpp"
#include "oatpp/web/protocol/http/outgoing/ResponseFactory.hpp" #include "oatpp/web/protocol/http/outgoing/ResponseFactory.hpp"
#include "oatpp/core/collection/LinkedList.hpp"
#include "oatpp/core/utils/ConversionUtils.hpp" #include "oatpp/core/utils/ConversionUtils.hpp"
#include <list>
#include <unordered_map> #include <unordered_map>
namespace oatpp { namespace web { namespace server { namespace api { namespace oatpp { namespace web { namespace server { namespace api {
@ -104,7 +104,7 @@ public:
/** /**
* Convenience typedef for list of &id:oatpp::web::server::api::Endpoint;. * Convenience typedef for list of &id:oatpp::web::server::api::Endpoint;.
*/ */
typedef oatpp::collection::LinkedList<std::shared_ptr<Endpoint>> Endpoints; typedef std::list<std::shared_ptr<Endpoint>> Endpoints;
/** /**
* Convenience typedef for &id:oatpp::web::server::HttpRequestHandler;. * Convenience typedef for &id:oatpp::web::server::HttpRequestHandler;.
@ -369,7 +369,7 @@ protected:
std::shared_ptr<RequestHandler> getEndpointHandler(const std::string& endpointName); std::shared_ptr<RequestHandler> getEndpointHandler(const std::string& endpointName);
protected: protected:
std::shared_ptr<Endpoints> m_endpoints; std::shared_ptr<Endpoints> m_endpoints{std::make_shared<Endpoints>()};
std::shared_ptr<handler::ErrorHandler> m_errorHandler; std::shared_ptr<handler::ErrorHandler> m_errorHandler;
std::shared_ptr<handler::AuthorizationHandler> m_defaultAuthorizationHandler; std::shared_ptr<handler::AuthorizationHandler> m_defaultAuthorizationHandler;
std::shared_ptr<oatpp::data::mapping::ObjectMapper> m_defaultObjectMapper; std::shared_ptr<oatpp::data::mapping::ObjectMapper> m_defaultObjectMapper;
@ -378,9 +378,7 @@ protected:
const oatpp::String m_routerPrefix; const oatpp::String m_routerPrefix;
public: public:
ApiController(const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& defaultObjectMapper, const oatpp::String &routerPrefix = nullptr) ApiController(const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& defaultObjectMapper, const oatpp::String &routerPrefix = nullptr)
: m_endpoints(Endpoints::createShared()) : m_defaultObjectMapper(defaultObjectMapper)
, m_errorHandler(nullptr)
, m_defaultObjectMapper(defaultObjectMapper)
, m_routerPrefix(routerPrefix) , m_routerPrefix(routerPrefix)
{} {}
public: public:
@ -391,7 +389,7 @@ public:
const EndpointInfoBuilder& infoBuilder) const EndpointInfoBuilder& infoBuilder)
{ {
auto endpoint = Endpoint::createShared(handler, infoBuilder); auto endpoint = Endpoint::createShared(handler, infoBuilder);
endpoints->pushBack(endpoint); endpoints->push_back(endpoint);
return endpoint; return endpoint;
} }

View File

@ -51,7 +51,7 @@ std::shared_ptr<Pattern> Pattern::parse(p_char8 data, v_buff_size size){
if(i - lastPos > 0){ if(i - lastPos > 0){
auto part = Part::createShared(Part::FUNCTION_CONST, oatpp::String((const char*)&data[lastPos], i - lastPos, true)); auto part = Part::createShared(Part::FUNCTION_CONST, oatpp::String((const char*)&data[lastPos], i - lastPos, true));
result->m_parts->pushBack(part); result->m_parts->push_back(part);
} }
lastPos = i + 1; lastPos = i + 1;
@ -60,10 +60,10 @@ std::shared_ptr<Pattern> Pattern::parse(p_char8 data, v_buff_size size){
lastPos = i + 1; lastPos = i + 1;
if(size > lastPos){ if(size > lastPos){
auto part = Part::createShared(Part::FUNCTION_ANY_END, oatpp::String((const char*)&data[lastPos], size - lastPos, true)); auto part = Part::createShared(Part::FUNCTION_ANY_END, oatpp::String((const char*)&data[lastPos], size - lastPos, true));
result->m_parts->pushBack(part); result->m_parts->push_back(part);
}else{ }else{
auto part = Part::createShared(Part::FUNCTION_ANY_END, oatpp::String((v_buff_size)0)); auto part = Part::createShared(Part::FUNCTION_ANY_END, oatpp::String((v_buff_size)0));
result->m_parts->pushBack(part); result->m_parts->push_back(part);
} }
return result; return result;
@ -76,10 +76,10 @@ std::shared_ptr<Pattern> Pattern::parse(p_char8 data, v_buff_size size){
if(i > lastPos){ if(i > lastPos){
auto part = Part::createShared(Part::FUNCTION_VAR, oatpp::String((const char*)&data[lastPos], i - lastPos, true)); auto part = Part::createShared(Part::FUNCTION_VAR, oatpp::String((const char*)&data[lastPos], i - lastPos, true));
result->m_parts->pushBack(part); result->m_parts->push_back(part);
}else{ }else{
auto part = Part::createShared(Part::FUNCTION_VAR, oatpp::String((v_buff_size)0)); auto part = Part::createShared(Part::FUNCTION_VAR, oatpp::String((v_buff_size)0));
result->m_parts->pushBack(part); result->m_parts->push_back(part);
} }
lastPos = i + 1; lastPos = i + 1;
@ -92,7 +92,7 @@ std::shared_ptr<Pattern> Pattern::parse(p_char8 data, v_buff_size size){
if(i - lastPos > 0){ if(i - lastPos > 0){
auto part = Part::createShared(Part::FUNCTION_CONST, oatpp::String((const char*)&data[lastPos], i - lastPos, true)); auto part = Part::createShared(Part::FUNCTION_CONST, oatpp::String((const char*)&data[lastPos], i - lastPos, true));
result->m_parts->pushBack(part); result->m_parts->push_back(part);
} }
return result; return result;
@ -123,21 +123,15 @@ bool Pattern::match(const StringKeyLabel& url, MatchMap& matchMap) {
oatpp::parser::Caret caret(url.getData(), url.getSize()); oatpp::parser::Caret caret(url.getData(), url.getSize());
if(m_parts->count() == 0){ if (m_parts->empty()) {
return !caret.skipChar('/');
if(caret.skipChar('/')){
return false;
}
return true;
} }
auto curr = m_parts->getFirstNode(); auto curr = std::begin(*m_parts);
const auto end = std::end(*m_parts);
while(curr != nullptr){ while(curr != end){
const std::shared_ptr<Part>& part = curr->getData(); const std::shared_ptr<Part>& part = *curr;
curr = curr->getNext(); ++curr;
caret.skipChar('/'); caret.skipChar('/');
if(part->function == Part::FUNCTION_CONST){ if(part->function == Part::FUNCTION_CONST){
@ -147,7 +141,7 @@ bool Pattern::match(const StringKeyLabel& url, MatchMap& matchMap) {
} }
if(caret.canContinue() && !caret.isAtChar('/')){ if(caret.canContinue() && !caret.isAtChar('/')){
if(caret.isAtChar('?') && (curr == nullptr || curr->getData()->function == Part::FUNCTION_ANY_END)) { if(caret.isAtChar('?') && (curr == end || (*curr)->function == Part::FUNCTION_ANY_END)) {
matchMap.m_tail = StringKeyLabel(url.getMemoryHandle(), caret.getCurrData(), caret.getDataSize() - caret.getPosition()); matchMap.m_tail = StringKeyLabel(url.getMemoryHandle(), caret.getCurrData(), caret.getDataSize() - caret.getPosition());
return true; return true;
} }
@ -168,7 +162,7 @@ bool Pattern::match(const StringKeyLabel& url, MatchMap& matchMap) {
auto label = caret.putLabel(); auto label = caret.putLabel();
v_char8 a = findSysChar(caret); v_char8 a = findSysChar(caret);
if(a == '?') { if(a == '?') {
if(curr == nullptr || curr->getData()->function == Part::FUNCTION_ANY_END) { if(curr == end || (*curr)->function == Part::FUNCTION_ANY_END) {
matchMap.m_variables[part->text] = StringKeyLabel(url.getMemoryHandle(), label.getData(), label.getSize()); matchMap.m_variables[part->text] = StringKeyLabel(url.getMemoryHandle(), label.getData(), label.getSize());
matchMap.m_tail = StringKeyLabel(url.getMemoryHandle(), caret.getCurrData(), caret.getDataSize() - caret.getPosition()); matchMap.m_tail = StringKeyLabel(url.getMemoryHandle(), caret.getCurrData(), caret.getDataSize() - caret.getPosition());
return true; return true;
@ -183,20 +177,13 @@ bool Pattern::match(const StringKeyLabel& url, MatchMap& matchMap) {
} }
caret.skipChar('/'); caret.skipChar('/');
if(caret.canContinue()){ return !caret.canContinue();
return false;
}
return true;
} }
oatpp::String Pattern::toString() { oatpp::String Pattern::toString() {
auto stream = oatpp::data::stream::ChunkedBuffer::createShared(); auto stream = oatpp::data::stream::ChunkedBuffer::createShared();
auto curr = m_parts->getFirstNode(); for (const std::shared_ptr<Part>& part : *m_parts) {
while (curr != nullptr) {
const std::shared_ptr<Part>& part = curr->getData();
curr = curr->getNext();
if(part->function == Part::FUNCTION_CONST) { if(part->function == Part::FUNCTION_CONST) {
stream->writeSimple("/", 1); stream->writeSimple("/", 1);
stream->writeSimple(part->text); stream->writeSimple(part->text);

View File

@ -27,10 +27,9 @@
#include "oatpp/core/data/share/MemoryLabel.hpp" #include "oatpp/core/data/share/MemoryLabel.hpp"
#include "oatpp/core/collection/LinkedList.hpp"
#include "oatpp/core/parser/Caret.hpp" #include "oatpp/core/parser/Caret.hpp"
#include <list>
#include <unordered_map> #include <unordered_map>
namespace oatpp { namespace web { namespace url { namespace mapping { namespace oatpp { namespace web { namespace url { namespace mapping {
@ -98,14 +97,10 @@ private:
}; };
private: private:
std::shared_ptr<oatpp::collection::LinkedList<std::shared_ptr<Part>>> m_parts; std::shared_ptr<std::list<std::shared_ptr<Part>>> m_parts{std::make_shared<std::list<std::shared_ptr<Part>>>()};
private: private:
v_char8 findSysChar(oatpp::parser::Caret& caret); v_char8 findSysChar(oatpp::parser::Caret& caret);
public: public:
Pattern()
: m_parts(oatpp::collection::LinkedList<std::shared_ptr<Part>>::createShared())
{}
public:
static std::shared_ptr<Pattern> createShared(){ static std::shared_ptr<Pattern> createShared(){
return std::make_shared<Pattern>(); return std::make_shared<Pattern>();

View File

@ -7,8 +7,6 @@ add_executable(oatppAllTests
oatpp/core/base/CommandLineArgumentsTest.hpp oatpp/core/base/CommandLineArgumentsTest.hpp
oatpp/core/base/LoggerTest.cpp oatpp/core/base/LoggerTest.cpp
oatpp/core/base/LoggerTest.hpp oatpp/core/base/LoggerTest.hpp
oatpp/core/base/collection/LinkedListTest.cpp
oatpp/core/base/collection/LinkedListTest.hpp
oatpp/core/base/memory/MemoryPoolTest.cpp oatpp/core/base/memory/MemoryPoolTest.cpp
oatpp/core/base/memory/MemoryPoolTest.hpp oatpp/core/base/memory/MemoryPoolTest.hpp
oatpp/core/base/memory/PerfTest.cpp oatpp/core/base/memory/PerfTest.cpp

View File

@ -51,7 +51,6 @@
#include "oatpp/core/data/share/MemoryLabelTest.hpp" #include "oatpp/core/data/share/MemoryLabelTest.hpp"
#include "oatpp/core/data/buffer/ProcessorTest.hpp" #include "oatpp/core/data/buffer/ProcessorTest.hpp"
#include "oatpp/core/base/collection/LinkedListTest.hpp"
#include "oatpp/core/base/memory/MemoryPoolTest.hpp" #include "oatpp/core/base/memory/MemoryPoolTest.hpp"
#include "oatpp/core/base/memory/PerfTest.hpp" #include "oatpp/core/base/memory/PerfTest.hpp"
#include "oatpp/core/base/CommandLineArgumentsTest.hpp" #include "oatpp/core/base/CommandLineArgumentsTest.hpp"
@ -82,8 +81,6 @@ void runTests() {
OATPP_RUN_TEST(oatpp::test::memory::MemoryPoolTest); OATPP_RUN_TEST(oatpp::test::memory::MemoryPoolTest);
OATPP_RUN_TEST(oatpp::test::memory::PerfTest); OATPP_RUN_TEST(oatpp::test::memory::PerfTest);
OATPP_RUN_TEST(oatpp::test::collection::LinkedListTest);
OATPP_RUN_TEST(oatpp::test::core::data::share::MemoryLabelTest); OATPP_RUN_TEST(oatpp::test::core::data::share::MemoryLabelTest);
OATPP_RUN_TEST(oatpp::test::core::data::share::LazyStringMapTest); OATPP_RUN_TEST(oatpp::test::core::data::share::LazyStringMapTest);
OATPP_RUN_TEST(oatpp::test::core::data::share::StringTemplateTest); OATPP_RUN_TEST(oatpp::test::core::data::share::StringTemplateTest);

View File

@ -1,109 +0,0 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#include "LinkedListTest.hpp"
#include "oatpp/core/Types.hpp"
#include "oatpp/core/collection/LinkedList.hpp"
#include "oatpp-test/Checker.hpp"
#include <list>
namespace oatpp { namespace test { namespace collection {
namespace {
class TestObject : public oatpp::base::Countable {
public:
SHARED_OBJECT_POOL(TestObject_Pool2, TestObject, 32)
public:
TestObject()
{}
public:
static std::shared_ptr<TestObject> createShared2(){
return std::make_shared<TestObject>();
}
static std::shared_ptr<TestObject> createShared(){
return TestObject_Pool2::allocateShared();
}
};
void testListPerformance(v_int32 iterationsCount){
auto list = oatpp::collection::LinkedList<std::shared_ptr<TestObject>>::createShared();
for(v_int32 i = 0; i < iterationsCount; i++){
list->pushBack(TestObject::createShared());
}
auto curr = list->getFirstNode();
while (curr != nullptr) {
auto data = curr->getData();
curr = curr->getNext();
}
}
void testStdListPerformance(v_int32 iterationsCount){
std::list<std::shared_ptr<TestObject>> list;
for(v_int32 i = 0; i < iterationsCount; i++){
list.push_back(TestObject::createShared());
}
auto it = list.begin();
while (it != list.end()) {
auto data = *it;
it++;
}
}
}
void LinkedListTest::onRun() {
v_int32 iterationsCount = 100000;
{
PerformanceChecker checker("oatpp::collection::LinkedList pushBack time");
for(v_int32 i = 0; i < 10; i ++) {
testListPerformance(iterationsCount);
}
}
{
PerformanceChecker checker("std::list pushBack time");
for(v_int32 i = 0; i < 10; i ++) {
testStdListPerformance(iterationsCount);
}
}
}
}}}

View File

@ -1,42 +0,0 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#ifndef oatpp_test_base_collection_LinkedListTest_hpp
#define oatpp_test_base_collection_LinkedListTest_hpp
#include "oatpp-test/UnitTest.hpp"
namespace oatpp { namespace test { namespace collection {
class LinkedListTest : public UnitTest{
public:
LinkedListTest():UnitTest("TEST[oatpp::collection::LinkedListTest]"){}
void onRun() override;
};
}}}
#endif /* oatpp_test_base_collection_LinkedListTest_hpp */

View File

@ -24,7 +24,6 @@
#include "PerfTest.hpp" #include "PerfTest.hpp"
#include "oatpp/core/collection/LinkedList.hpp"
#include "oatpp/core/Types.hpp" #include "oatpp/core/Types.hpp"
#include "oatpp/core/concurrency/Thread.hpp" #include "oatpp/core/concurrency/Thread.hpp"