Skip to content

Commit

Permalink
Move private inline function definitions to src directory
Browse files Browse the repository at this point in the history
  • Loading branch information
OTheDev committed Mar 3, 2024
1 parent 987361d commit e68757a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 33 deletions.
34 changes: 1 addition & 33 deletions include/impl-bi.inl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ SPDX-License-Identifier: Apache-2.0

#include "bi.hpp"

#include <cassert>
#include <utility>

namespace bi {
Expand Down Expand Up @@ -58,44 +57,13 @@ inline int bi_t::sign() const noexcept {
}

inline bool bi_t::odd() const noexcept {
return size() == 0 ? false : (*this)[0] & 1;
return size() == 0 ? false : vec_[0] & 1;
}

inline bool bi_t::even() const noexcept { return !odd(); }

///@}

/**
* @name Internal modifiers for the digit vector
*/
///@{

inline void bi_t::reserve_(size_t new_capacity) { vec_.reserve(new_capacity); }

inline void bi_t::resize_(size_t new_size) { vec_.resize(new_size); }

inline digit& bi_t::operator[](size_t index) { return vec_[index]; }

inline const digit& bi_t::operator[](size_t index) const { return vec_[index]; }

inline void bi_t::resize_unsafe_(size_t new_size) {
assert(new_size <= vec_.capacity());
vec_.resize_unsafe(new_size);
}

inline void bi_t::trim_trailing_zeros() noexcept {
size_t new_size = vec_.size();
while (new_size > 0 && vec_[new_size - 1] == 0) {
--new_size;
}
vec_.resize(new_size);
if (new_size == 0) {
negative_ = false;
}
}

///@}

} // namespace bi

#endif // BI_INCLUDE_IMPL_BI_INL_
5 changes: 5 additions & 0 deletions src/bi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ SPDX-License-Identifier: Apache-2.0

#include "bi.hpp"

#include <algorithm>
#include <compare>
#include <iostream>
#include <limits>
#include <string>
#include <utility>
#include <version>
#if defined(__cpp_lib_format)
#include <format>
#define HAS_STD_FORMAT
#endif

#include "bi.inl"
#include "h_.hpp"
#include "inst_integral.hpp"
#include "uints.hpp"
Expand Down
48 changes: 48 additions & 0 deletions src/bi.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright 2024 Owain Davies
SPDX-License-Identifier: Apache-2.0
*/

#ifndef BI_SRC_BI_INL_
#define BI_SRC_BI_INL_

#include "bi.hpp"

#include <cassert>

namespace bi {

/**
* @name Internal modifiers for the digit vector
*/
///@{

inline void bi_t::reserve_(size_t new_capacity) { vec_.reserve(new_capacity); }

inline void bi_t::resize_(size_t new_size) { vec_.resize(new_size); }

inline digit& bi_t::operator[](size_t index) { return vec_[index]; }

inline const digit& bi_t::operator[](size_t index) const { return vec_[index]; }

inline void bi_t::resize_unsafe_(size_t new_size) {
assert(new_size <= vec_.capacity());
vec_.resize_unsafe(new_size);
}

inline void bi_t::trim_trailing_zeros() noexcept {
size_t new_size = vec_.size();
while (new_size > 0 && vec_[new_size - 1] == 0) {
--new_size;
}
vec_.resize(new_size);
if (new_size == 0) {
negative_ = false;
}
}

///@}

} // namespace bi

#endif // BI_SRC_BI_INL_

0 comments on commit e68757a

Please sign in to comment.