[Scummvm-cvs-logs] SF.net SVN: scummvm: [29523] scummvm/trunk/common/algorithm.h
lordhoto at users.sourceforge.net
lordhoto at users.sourceforge.net
Sat Nov 17 01:19:27 CET 2007
Revision: 29523
http://scummvm.svn.sourceforge.net/scummvm/?rev=29523&view=rev
Author: lordhoto
Date: 2007-11-16 16:19:27 -0800 (Fri, 16 Nov 2007)
Log Message:
-----------
Added 'specialized' versions of set_to for char*, signed char* and unsigned char* 'In' parameters.
Modified Paths:
--------------
scummvm/trunk/common/algorithm.h
Modified: scummvm/trunk/common/algorithm.h
===================================================================
--- scummvm/trunk/common/algorithm.h 2007-11-16 23:39:14 UTC (rev 29522)
+++ scummvm/trunk/common/algorithm.h 2007-11-17 00:19:27 UTC (rev 29523)
@@ -53,8 +53,29 @@
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)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list