diff --git a/include/dsn/cpp/json_helper.h b/include/dsn/cpp/json_helper.h index 3062df9687..feeaf712f9 100644 --- a/include/dsn/cpp/json_helper.h +++ b/include/dsn/cpp/json_helper.h @@ -550,10 +550,7 @@ class json_forwarder { std::ostringstream os; encode(os, t); - std::string *result = new std::string(os.str()); - return dsn::blob(std::shared_ptr(const_cast(result->c_str()), - [result](char *) { delete result; }), - result->length()); + return blob::create_from_bytes(os.str()); } static bool decode(const JsonObject &in, T &t) diff --git a/include/dsn/tool-api/task_spec.h b/include/dsn/tool-api/task_spec.h index 42649daa11..2aa78b1e42 100644 --- a/include/dsn/tool-api/task_spec.h +++ b/include/dsn/tool-api/task_spec.h @@ -39,7 +39,6 @@ #include #include #include -#include #include #include #include diff --git a/include/dsn/utility/singleton_vector_store.h b/include/dsn/utility/singleton_vector_store.h deleted file mode 100644 index 49c9f72866..0000000000 --- a/include/dsn/utility/singleton_vector_store.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 Microsoft Corporation - * - * -=- Robust Distributed System Nucleus (rDSN) -=- - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -/* - * Description: - * What is this file about? - * - * Revision history: - * xxxx-xx-xx, author, first version - * xxxx-xx-xx, author, fix bug about xxx - */ - -#pragma once - -#include -#include - -namespace dsn { -namespace utils { - -template -class singleton_vector_store - : public dsn::utils::singleton> -{ -public: - singleton_vector_store(void) {} - ~singleton_vector_store(void) {} - - bool contains(int index) const - { - if (index >= static_cast(_contains.size())) - return false; - else - return _contains[index]; - } - - T get(int index) const - { - if (index >= static_cast(_contains.size())) - return default_value; - else - return _values[index]; - } - - bool put(int index, T value) - { - if (index >= static_cast(_contains.size())) { - for (int i = static_cast(_contains.size()); i < index; i++) { - _contains.push_back(false); - _values.push_back(default_value); - } - - _contains.push_back(true); - _values.push_back(value); - return true; - } else if (_contains[index]) - return false; - else { - _contains[index] = true; - _values[index] = value; - return true; - } - } - -private: - std::vector _contains; - std::vector _values; -}; -} -} // end namespace dsn::utils diff --git a/src/core/core/task_spec.cpp b/src/core/core/task_spec.cpp index 4de6979a43..d484eeb6cb 100644 --- a/src/core/core/task_spec.cpp +++ b/src/core/core/task_spec.cpp @@ -34,24 +34,26 @@ */ #include -#include -#include #include #include -#include -#include -#include +#include namespace dsn { +constexpr int TASK_SPEC_STORE_CAPACITY = 512; + +// A sequential storage maps task_code to task_spec. +static std::array, TASK_SPEC_STORE_CAPACITY> s_task_spec_store; + void task_spec::register_task_code(task_code code, dsn_task_type_t type, dsn_task_priority_t pri, dsn::threadpool_code pool) { - if (!dsn::utils::singleton_vector_store::instance().contains(code)) { - task_spec *spec = new task_spec(code, code.to_string(), type, pri, pool); - dsn::utils::singleton_vector_store::instance().put(code, spec); + dassert(code < TASK_SPEC_STORE_CAPACITY, "code = %d", code); + if (!s_task_spec_store[code]) { + s_task_spec_store[code] = make_unique(code, code.to_string(), type, pri, pool); + auto &spec = s_task_spec_store[code]; if (type == TASK_TYPE_RPC_REQUEST) { std::string ack_name = std::string(code.to_string()) + std::string("_ACK"); @@ -114,7 +116,7 @@ void task_spec::register_storage_task_code(task_code code, task_spec *task_spec::get(int code) { - return dsn::utils::singleton_vector_store::instance().get(code); + return code < TASK_SPEC_STORE_CAPACITY ? s_task_spec_store[code].get() : nullptr; } task_spec::task_spec(int code,