I don't know about cheating, but memmove
basically does what your loop does, only more efficiently.
Besides, it's one of the most basic utility functions, so I don't see why you should not use it.
As for complexity, the order of the algorithm will not change, it will simply be faster. memmove
is implemented in assembly and tries to make full use of the alignment to copy word per word instead of byte per byte.
EDIT:
well okay, there might be cases where the manual copy might be a couple of instructions shorter than the call to memmove
, but if you start moving data around in memory, you're doing an inherently costly operation, so optimizing a couple of CPU cycles away will not make any difference in the big picture.
If your design involves in-place moves for performance-critical data, you would be better off changing the underlying data structure for something that avoids copies altogether (list, tree, hash table, whatever).