~nloomans/inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
4

[PATCH] improvement: made memset faster for long sizes

Liewe Gutter
Details
Message ID
<20200309140548.28354-1-liewegutter@gmail.com>
DKIM signature
pass
Download raw message
Patch: +16 -1
made memset significantly faster for very long strings.
Memory will now be set in chunks of the size of an unsigned long long,
until there are less characters left than the chunk size.
---
 src/ft_memset.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/ft_memset.c b/src/ft_memset.c
index 83617b4..53975d4 100644
--- a/src/ft_memset.c
+++ b/src/ft_memset.c
@@ -14,9 +14,24 @@

void	*ft_memset(void *b, int c, size_t len)
{
	size_t	i;
	size_t				i;
	size_t				chunk_size;
	unsigned long long	chunk;

	chunk_size = sizeof(unsigned long long);
	i = chunk_size / sizeof(unsigned char);
	while (i > 0)
	{
		chunk <<= 8;
		chunk |= (unsigned long long)(unsigned char)c;
		i--;
	}
	i = 0;
	while (len >= chunk_size && i < (len - chunk_size))
	{
		*(unsigned long long *)&(((unsigned char *)b)[i]) = chunk;
		i += chunk_size;
	}
	while (i < len)
	{
		((unsigned char *)b)[i] = (unsigned char)c;
-- 
2.17.1
Details
Message ID
<C16D8G9QQ7UG.3DHFKXQ0AWKAM@f1r3s17.codam.nl>
In-Reply-To
<20200309140548.28354-1-liewegutter@gmail.com> (view parent)
DKIM signature
missing
Download raw message
It failed to compile for me:

[39/65] Compiling C object 'ft@sta/src_ft_memset.c.o'.
FAILED: ft@sta/src_ft_memset.c.o
cc -Ift@sta -I. -I.. -I../inc -Xclang -fcolor-diagnostics -pipe -Wall -Winvalid-pch -Wextra -Wpedantic -Werror -std=c99 -g -MD -MQ 'ft@sta/src_ft_memset.c.o' -MF 'ft@sta/src_ft_memset.c.o.d' -o 'ft@sta/src_ft_memset.c.o' -c ../src/ft_memset.c
../src/ft_memset.c:25:3: error: variable 'chunk' is uninitialized when used here [-Werror,-Wuninitialized]
                chunk <<= 8;
                ^~~~~
../src/ft_memset.c:19:26: note: initialize the variable 'chunk' to silence this warning
        unsigned long long      chunk;
                                     ^
                                      = 0
1 error generated.
[44/65] Compiling C object 'ft@sta/src_ft_strclr.c.o'.
ninja: build stopped: subcommand failed.

On Mon Mar 9, 2020 at 3:05 PM, Liewe Gutter wrote:
> made memset significantly faster for very long strings.
> Memory will now be set in chunks of the size of an unsigned long long,
> until there are less characters left than the chunk size.

The first line of the commit message is pretty much the same as the
commit title.
Review patch Export thread (mbox)