1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-07-03 08:10:31 +02:00

Remove superfluous type check in bitvector->list

This commit is contained in:
Daniel Llorens 2020-02-13 10:22:53 +01:00
parent 3b6a2f281a
commit 5a2f73faf5
2 changed files with 11 additions and 15 deletions

View file

@ -36,7 +36,7 @@
#include "bitvectors.h" #include "bitvectors.h"
/* FIXME move functions using these (operating on rank-1 bit arrays, not /* FIXME move functions using these (operating on rank-1 bit arrays, not
bitvectors) to a separate source file bitvectors) to a separate source file.
*/ */
#include "arrays.h" #include "arrays.h"
#include "srfi-4.h" #include "srfi-4.h"
@ -257,7 +257,7 @@ scm_c_bitvector_set_x (SCM vec, size_t idx, SCM val)
if (idx >= len) if (idx >= len)
scm_out_of_range (NULL, scm_from_size_t (idx)); scm_out_of_range (NULL, scm_from_size_t (idx));
bitset_(bits, idx, scm_is_true (val)); bitset_ (bits, idx, scm_is_true (val));
} }
SCM_DEFINE (scm_bitvector_set_x, "bitvector-set!", 3, 0, 0, SCM_DEFINE (scm_bitvector_set_x, "bitvector-set!", 3, 0, 0,
@ -303,7 +303,7 @@ SCM_DEFINE (scm_bitvector_fill_x, "bitvector-fill!", 2, 0, 0,
{ {
size_t i; size_t i;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
bitset_(bits, off+i*inc, scm_is_true(val)); bitset_ (bits, off+i*inc, scm_is_true(val));
} }
return SCM_UNSPECIFIED; return SCM_UNSPECIFIED;
@ -319,7 +319,7 @@ SCM_DEFINE (scm_list_to_bitvector, "list->bitvector", 1, 0, 0,
size_t bit_len = scm_to_size_t (scm_length (list)); size_t bit_len = scm_to_size_t (scm_length (list));
SCM vec = scm_c_make_bitvector (bit_len, SCM_UNDEFINED); SCM vec = scm_c_make_bitvector (bit_len, SCM_UNDEFINED);
size_t word_len = (bit_len+31)/32; size_t word_len = (bit_len+31)/32;
uint32_t *bits = scm_bitvector_writable_elements (vec, NULL); uint32_t *bits = BITVECTOR_BITS (vec);
size_t i, j; size_t i, j;
for (i = 0; i < word_len && scm_is_pair (list); i++, bit_len -= 32) for (i = 0; i < word_len && scm_is_pair (list); i++, bit_len -= 32)
@ -478,8 +478,7 @@ SCM_DEFINE (scm_bit_position, "bit-position", 3, 0, 0,
size_t word_len = (len + 31) / 32; size_t word_len = (len + 31) / 32;
uint32_t last_mask = ((uint32_t)-1) >> (32*word_len - len); uint32_t last_mask = ((uint32_t)-1) >> (32*word_len - len);
size_t first_word = first_bit / 32; size_t first_word = first_bit / 32;
uint32_t first_mask = uint32_t first_mask = ((uint32_t)-1) << (first_bit - 32*first_word);
((uint32_t)-1) << (first_bit - 32*first_word);
uint32_t w; uint32_t w;
for (size_t i = first_word; i < word_len; i++) for (size_t i = first_word; i < word_len; i++)
@ -499,13 +498,11 @@ SCM_DEFINE (scm_bit_position, "bit-position", 3, 0, 0,
else else
{ {
for (size_t i = first_bit; i < len; i++) for (size_t i = first_bit; i < len; i++)
{ if (bit == bitref_ (bits, off+i*inc))
if (bit == bitref_ (bits, off+i*inc)) {
{ res = scm_from_size_t (i);
res = scm_from_size_t (i); break;
break; }
}
}
} }
return res; return res;

View file

@ -36,9 +36,8 @@
#include <gmp.h> #include <gmp.h>
/* FIXME want to remove this dependence out. See bitvectors.h */ /* FIXME want to remove this dependence. See bitvectors.h */
#include "array-handle.h" #include "array-handle.h"
#include "arrays.h"
#include "boolean.h" #include "boolean.h"
#include "dynwind.h" #include "dynwind.h"
#include "extensions.h" #include "extensions.h"