Skip to content

Commit

Permalink
add align_up helper
Browse files Browse the repository at this point in the history
  • Loading branch information
cmazakas committed Mar 6, 2024
1 parent 417c8b8 commit a6687dc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
32 changes: 32 additions & 0 deletions src/detail/align_up.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Copyright (c) 2024 Christian Mazakas
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/CPPAlliance/http_proto
//

#ifndef BOOST_HTTP_PROTO_DETAIL_ALIGN_UP_HPP
#define BOOST_HTTP_PROTO_DETAIL_ALIGN_UP_HPP

#include <cstddef>

namespace boost {
namespace http_proto {
namespace detail {

constexpr
inline
std::size_t
align_up(std::size_t s, std::size_t A)
{
return A * (
(s + A - 1) / A);
}

} // detail
} // http_proto
} // boost

#endif
6 changes: 3 additions & 3 deletions src/detail/header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <string>
#include <utility>

#include "align_up.hpp"

namespace boost {
namespace http_proto {
namespace detail {
Expand Down Expand Up @@ -209,9 +211,7 @@ bytes_needed(
size = 19;
static constexpr auto A =
alignof(header::entry);
// round up to alignof(A)
return A * (
(size + A - 1) / A) +
return align_up(size, A) +
(count * sizeof(
header::entry));
}
Expand Down

0 comments on commit a6687dc

Please sign in to comment.