Ver código fonte

optimize sigisemptyset

the static const zero set ended up getting put in bss instead of
rodata, wasting writable memory, and the call to memcmp was
size-inefficient. generally for nonstandard extension functions we try
to avoid poking at any internals directly, but the way the zero set
was setup was arguably already doing so.
Rich Felker 6 anos atrás
pai
commit
941bd884cc
1 arquivos alterados com 3 adições e 2 exclusões
  1. 3 2
      src/signal/sigisemptyset.c

+ 3 - 2
src/signal/sigisemptyset.c

@@ -4,6 +4,7 @@
 
 int sigisemptyset(const sigset_t *set)
 {
-	static const unsigned long zeroset[_NSIG/8/sizeof(long)];
-	return !memcmp(set, &zeroset, _NSIG/8);
+	for (size_t i=0; i<_NSIG/8/sizeof *set->__bits; i++)
+		if (set->__bits[i]) return 0;
+	return 1;
 }