[Commits] [wesnoth/wesnoth] 1c28c5: Add `bit_width` functions

GitHub noreply at github.com
Tue Apr 1 02:39:55 UTC 2014


  Branch: refs/heads/master
  Home:   https://github.com/wesnoth/wesnoth
  Commit: 1c28c514a95b7c61ec4a9bd84e7437313448914a
      https://github.com/wesnoth/wesnoth/commit/1c28c514a95b7c61ec4a9bd84e7437313448914a
  Author: 8573 <8573dd at gmail.com>
  Date:   2014-03-20 (Thu, 20 Mar 2014)

  Changed paths:
    M src/tests/test_util.cpp
    M src/util.hpp

  Log Message:
  -----------
  Add `bit_width` functions

Add the following functions in `src/util.hpp`:

    template<typename T> inline std::size_t bit_width();
    template<typename T> inline std::size_t bit_width(T x);

These functions compute the size, in bits, of a type or value, providing
a convenient and self-documenting name for the underlying expression,
`sizeof(…) * std::numeric_limits<unsigned char>::digits`.

This commit adds two additional header `#include` directives in
`src/util.hpp`. The newly included headers are as follows:

  - `<cstddef>`, for `std::size_t`; and
  - `<limits>`, for `std::numeric_limits`.

At first, I obtained the bit width of a byte using the C preprocessor
macro `CHAR_BIT`, defined in the C standard library header `<climits>`,
rather than using `std::numeric_limits<unsigned char>::digits`, but I
subsequently switched to using `std::numeric_limits` per Soliton’s
recommendation at 2014-03-17 21:36Z in the `#wesnoth-dev` IRC channel on
the freenode IRC network (<irc://chat.freenode.net/%23wesnoth-dev>).


  Commit: 231320183770705dbc81509e7152a45c8cc7b3fa
      https://github.com/wesnoth/wesnoth/commit/231320183770705dbc81509e7152a45c8cc7b3fa
  Author: 8573 <8573dd at gmail.com>
  Date:   2014-03-22 (Sat, 22 Mar 2014)

  Changed paths:
    M src/util.hpp

  Log Message:
  -----------
  Have `bit_width(x)` take `x` by reference.

In `src/util.hpp`, change the following function signature:

    template<typename T> inline std::size_t bit_width(T x);

To the following function signature:

    template<typename T> inline std::size_t bit_width(const T& x);

This avoids needing to call `T`’s copy-constructor, which could be
annoying.


  Commit: 23fddb0e93dae8a241fc8234710016c00a4bec14
      https://github.com/wesnoth/wesnoth/commit/23fddb0e93dae8a241fc8234710016c00a4bec14
  Author: 8573 <8573dd at gmail.com>
  Date:   2014-03-22 (Sat, 22 Mar 2014)

  Changed paths:
    M src/tests/test_util.cpp
    M src/util.hpp

  Log Message:
  -----------
  Add `count_ones` function

Add the following function in `src/util.hpp`:

    template<typename N> inline unsigned int count_ones(N n);

This function returns the quantity of `1` bits in `n` — i.e., `n`’s
population count.


  Commit: 97d24001eba81c15ea02e750d4bc21ad17569e13
      https://github.com/wesnoth/wesnoth/commit/97d24001eba81c15ea02e750d4bc21ad17569e13
  Author: 8573 <8573dd at gmail.com>
  Date:   2014-03-22 (Sat, 22 Mar 2014)

  Changed paths:
    M src/tests/test_util.cpp
    M src/util.hpp

  Log Message:
  -----------
  Add `count_leading_zeros` function

Add the following function in `src/util.hpp`:

    template<typename N> inline unsigned int count_leading_zeros(N n);

This function returns the quantity of leading `0` bits in `n`.


  Commit: 36e3da74ebd09c7d07e5e524fd1d75ac0095db41
      https://github.com/wesnoth/wesnoth/commit/36e3da74ebd09c7d07e5e524fd1d75ac0095db41
  Author: 8573 <8573dd at gmail.com>
  Date:   2014-03-22 (Sat, 22 Mar 2014)

  Changed paths:
    M src/tests/test_util.cpp
    M src/util.hpp

  Log Message:
  -----------
  Add `count_leading_ones` function

Add the following function in `src/util.hpp`:

    template<typename N> inline unsigned int count_leading_ones(N n);

This function returns the quantity of leading `1` bits in `n`.


  Commit: 188c7c338619bb645cd60767cdf58a9885c5776f
      https://github.com/wesnoth/wesnoth/commit/188c7c338619bb645cd60767cdf58a9885c5776f
  Author: aquileia <sk.aquileia at gmail.com>
  Date:   2014-03-23 (Sun, 23 Mar 2014)

  Changed paths:
    M src/tests/test_util.cpp
    M src/util.hpp

  Log Message:
  -----------
  Merge branch '8573/util/count-leading-ones/1' of https://github.com/8680-wesnoth/wesnoth into codepoint_count


  Commit: 8e2edc82a0df09aa71bfe6ea637ef701c6087abd
      https://github.com/wesnoth/wesnoth/commit/8e2edc82a0df09aa71bfe6ea637ef701c6087abd
  Author: aquileia <sk.aquileia at gmail.com>
  Date:   2014-03-23 (Sun, 23 Mar 2014)

  Changed paths:
    M src/serialization/string_utils.cpp

  Log Message:
  -----------
  Improve byte_size_from_utf8_first()

The count_leading_ones function by 8680 improves speed and readability
of this function which parses UTF-8 characters.


  Commit: 66058c10efbc0b958fa1e5535a5e761dfdcb7650
      https://github.com/wesnoth/wesnoth/commit/66058c10efbc0b958fa1e5535a5e761dfdcb7650
  Author: Alexander van Gessel <ai0867 at gmail.com>
  Date:   2014-04-01 (Tue, 01 Apr 2014)

  Changed paths:
    M src/serialization/unicode.cpp
    M src/tests/test_util.cpp
    M src/util.hpp

  Log Message:
  -----------
  Merge branch 'codepoint_count' (PR #128) from aquileia/wesnoth-old

Conflicts:
	src/serialization/string_utils.cpp


Compare: https://github.com/wesnoth/wesnoth/compare/d69d4e9858fe...66058c10efbc


More information about the Commits mailing list