diff options
author | Johannes Schickel | 2007-11-17 00:19:27 +0000 |
---|---|---|
committer | Johannes Schickel | 2007-11-17 00:19:27 +0000 |
commit | cec8b9820158d7769898f07f3202adfdcd1e1af6 (patch) | |
tree | d99eb421264eda1121e90f7bc4ee803fbae34219 | |
parent | 31180e79813f5e654a7b2ca7d740074d8e99d1d2 (diff) | |
download | scummvm-rg350-cec8b9820158d7769898f07f3202adfdcd1e1af6.tar.gz scummvm-rg350-cec8b9820158d7769898f07f3202adfdcd1e1af6.tar.bz2 scummvm-rg350-cec8b9820158d7769898f07f3202adfdcd1e1af6.zip |
Added 'specialized' versions of set_to for char*, signed char* and unsigned char* 'In' parameters.
svn-id: r29523
-rw-r--r-- | common/algorithm.h | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/common/algorithm.h b/common/algorithm.h index fccc815b36..6e6c6691ed 100644 --- a/common/algorithm.h +++ b/common/algorithm.h @@ -53,8 +53,29 @@ Out copy_if(In first, In last, Out dst, Op op) { return dst; } -// TODO: this is can be slower than memset for most normal data -// maybe specialize the template for char, short, int, long, long long +// Our 'specialized' 'set_to' template for char, signed char and unsigned char arrays. +// Since C++ doesn't support partial specialized template functions (currently) we +// are going this way... +// With this we assure the usage of memset for those, which should be +// faster than a simple loop like for the generic 'set_to'. +template<class Value> +signed char *set_to(signed char *first, signed char *last, Value val) { + memset(first, (val & 0xFF), last - first); + return last; +} + +template<class Value> +unsigned char *set_to(unsigned char *first, unsigned char *last, Value val) { + memset(first, (val & 0xFF), last - first); + return last; +} + +template<class Value> +char *set_to(char *first, char *last, Value val) { + memset(first, (val & 0xFF), last - first); + return last; +} + template<class In, class Value> In set_to(In first, In last, Value val) { while (first != last) |