Improve compile times by a huge amount

This commit is contained in:
rexy712 2020-03-23 10:14:30 -07:00
parent 066d875f91
commit 15f3592270
3 changed files with 40 additions and 5 deletions

View File

@ -22,9 +22,9 @@
#include <cstdlib> //size_t #include <cstdlib> //size_t
#include <utility> //move #include <utility> //move
#include <cstring> //memcpy #include <cstring> //memcpy
#include <algorithm> //max
#include <type_traits> #include <type_traits>
#include <new> #include <new>
#include <rexy/detail/util.hpp> //max
#include <rexy/detail/default_allocator.hpp> #include <rexy/detail/default_allocator.hpp>
namespace rexy{ namespace rexy{
@ -124,7 +124,7 @@ namespace rexy{
} }
void append(const char* data, size_t len){ void append(const char* data, size_t len){
if(m_size + len > m_cap) 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); memcpy(m_data+m_size, data, len);
m_size += len; m_size += len;
} }

34
rexy/detail/util.hpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef REXY_DETAIL_UTIL_HPP
#define REXY_DETAIL_UTIL_HPP
namespace rexy::detail{
//including <algorithm> causes long compile times. so just make my own max instead
template<class T>
constexpr const T& max(const T& a, const T& b){
return (a < b) ? b : a;
}
template<class T>
constexpr const T& min(const T& a, const T& b){
return (a > b) ? b : a;
}
}
#endif

View File

@ -22,7 +22,8 @@
#include <utility> //forward, move, swap, etc #include <utility> //forward, move, swap, etc
#include <cstdlib> //memcpy #include <cstdlib> //memcpy
#include <cstring> //strlen, strcpy #include <cstring> //strlen, strcpy
#include <algorithm> //max
#include <rexy/detail/util.hpp> //max
namespace rexy{ namespace rexy{
template<class Allocator> template<class Allocator>
@ -137,7 +138,7 @@ namespace rexy{
m_length += len; m_length += len;
m_data[m_length] = 0; m_data[m_length] = 0;
}else{ }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_data, m_length);
memcpy(tmp.m_data+m_length, data, len); memcpy(tmp.m_data+m_length, data, len);
tmp.m_length = len+m_length; tmp.m_length = len+m_length;
@ -167,7 +168,7 @@ namespace rexy{
strcpy(m_data, s); strcpy(m_data, s);
}else{ }else{
Allocator::free(m_data); Allocator::free(m_data);
m_cap = std::max(len, m_cap*2); m_cap = detail::max(len, m_cap*2);
m_data = reinterpret_cast<char*>(Allocator::copy(s, m_cap+1)); m_data = reinterpret_cast<char*>(Allocator::copy(s, m_cap+1));
if(!m_data){ if(!m_data){
m_length = 0; m_length = 0;