From 15f35922707a9975c91ee416c4884552bec56453 Mon Sep 17 00:00:00 2001 From: rexy712 Date: Mon, 23 Mar 2020 10:14:30 -0700 Subject: [PATCH] Improve compile times by a huge amount --- rexy/binary.hpp | 4 ++-- rexy/detail/util.hpp | 34 ++++++++++++++++++++++++++++++++++ rexy/string_base.tpp | 7 ++++--- 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 rexy/detail/util.hpp diff --git a/rexy/binary.hpp b/rexy/binary.hpp index 87ee3a7..f68c251 100644 --- a/rexy/binary.hpp +++ b/rexy/binary.hpp @@ -22,9 +22,9 @@ #include //size_t #include //move #include //memcpy -#include //max #include #include +#include //max #include namespace rexy{ @@ -124,7 +124,7 @@ namespace rexy{ } void append(const char* data, size_t len){ if(m_size + len > m_cap) - resize(std::max(m_cap*2, m_size+len)); + resize(detail::max(m_cap*2, m_size+len)); memcpy(m_data+m_size, data, len); m_size += len; } diff --git a/rexy/detail/util.hpp b/rexy/detail/util.hpp new file mode 100644 index 0000000..a25dca3 --- /dev/null +++ b/rexy/detail/util.hpp @@ -0,0 +1,34 @@ +/** + This file is a part of rexy's general purpose library + Copyright (C) 2020 rexy712 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +#ifndef REXY_DETAIL_UTIL_HPP +#define REXY_DETAIL_UTIL_HPP + +namespace rexy::detail{ + //including causes long compile times. so just make my own max instead + template + constexpr const T& max(const T& a, const T& b){ + return (a < b) ? b : a; + } + template + constexpr const T& min(const T& a, const T& b){ + return (a > b) ? b : a; + } +} + +#endif diff --git a/rexy/string_base.tpp b/rexy/string_base.tpp index bfa2b0f..f68836f 100644 --- a/rexy/string_base.tpp +++ b/rexy/string_base.tpp @@ -22,7 +22,8 @@ #include //forward, move, swap, etc #include //memcpy #include //strlen, strcpy -#include //max + +#include //max namespace rexy{ template @@ -137,7 +138,7 @@ namespace rexy{ m_length += len; m_data[m_length] = 0; }else{ - string_intermediary tmp(std::max(m_length + len, m_cap*2)); + string_intermediary tmp(detail::max(m_length + len, m_cap*2)); memcpy(tmp.m_data, m_data, m_length); memcpy(tmp.m_data+m_length, data, len); tmp.m_length = len+m_length; @@ -167,7 +168,7 @@ namespace rexy{ strcpy(m_data, s); }else{ Allocator::free(m_data); - m_cap = std::max(len, m_cap*2); + m_cap = detail::max(len, m_cap*2); m_data = reinterpret_cast(Allocator::copy(s, m_cap+1)); if(!m_data){ m_length = 0;