From d02bd0eb656b885bdf48088529183c40df8bd9c1 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 24 Aug 2025 09:33:51 +0200 Subject: feat: lib: micro-optimizations and improvements. Signed-off-by: Amlal El Mahrouss --- dev/lib/logic/equiv.hpp | 10 ++++++---- dev/lib/memory/tracked_ptr.hpp | 6 +++--- dev/lib/utility/cgi_writer.hpp | 14 ++++++++++---- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/dev/lib/logic/equiv.hpp b/dev/lib/logic/equiv.hpp index 2f63673..75fd8ee 100644 --- a/dev/lib/logic/equiv.hpp +++ b/dev/lib/logic/equiv.hpp @@ -7,6 +7,7 @@ #pragma once +/// @brief SOCL equivalence namespace. namespace snu::equiv { template @@ -59,7 +60,7 @@ namespace snu::equiv struct equiv_is_int8 { private: - T left_ = 255, right_ = 255; + T left_ = 127, right_ = 127; public: using result = T; @@ -74,7 +75,8 @@ namespace snu::equiv struct equiv_not_int8 { private: - T left_ = 255, right_ = 255; + // these shall overflow if not int8. + T left_ = 127, right_ = 127; public: using result = T; @@ -96,7 +98,7 @@ namespace snu::equiv constexpr result hash() { - return left_ / right_; + return left_ / right_ == 1; } }; -} // namespace snu::equiv \ No newline at end of file +} // namespace snu::equiv diff --git a/dev/lib/memory/tracked_ptr.hpp b/dev/lib/memory/tracked_ptr.hpp index 2607b5b..da7e46c 100644 --- a/dev/lib/memory/tracked_ptr.hpp +++ b/dev/lib/memory/tracked_ptr.hpp @@ -194,9 +194,9 @@ namespace snu::memory }; template - inline auto make_tracked(T arg) -> tracked_ptr + inline auto make_tracked() -> tracked_ptr { - return tracked_ptr(std::forward(arg)); + return tracked_ptr(); } template @@ -220,4 +220,4 @@ namespace snu::memory ::kill(::getpid(), SIGTRAP); } } -} // namespace snu::memory \ No newline at end of file +} // namespace snu::memory diff --git a/dev/lib/utility/cgi_writer.hpp b/dev/lib/utility/cgi_writer.hpp index 2c30adf..69d0170 100644 --- a/dev/lib/utility/cgi_writer.hpp +++ b/dev/lib/utility/cgi_writer.hpp @@ -4,8 +4,8 @@ * Copyright 2023-2025, Amlal El Mahrouss. */ -#ifndef _SNU_CGI_HPP -#define _SNU_CGI_HPP +#ifndef _SNU_CGI_WRITER_HPP +#define _SNU_CGI_WRITER_HPP #include #include @@ -25,7 +25,13 @@ namespace snu std::printf("Content-Type: %s\r\n", mime.c_str()); std::printf("Server: %s\r\n", "socl-cgi-system"); std::printf("Content-Length: %ld\r\n\r\n", ss.str().size()); - std::printf("%s", ss.str().c_str()); + + auto ss_cc = ss.str(); + + for (auto& ch : ss_cc) + { + std::printf("%c", ch); + } return *this; } @@ -66,4 +72,4 @@ namespace snu } // namespace cgi } // namespace snu -#endif // ifndef _SNU_CGI_HPP \ No newline at end of file +#endif // ifndef _SNU_CGI_WRITER_HPP -- cgit v1.2.3