Skip to content

Commit

Permalink
lib/random: Make some functions in random.c inline
Browse files Browse the repository at this point in the history
random_range, random_uint8 and random_uint16 are basically just wrappers
around random_uint32. Hence, don't export these functions so the compiler
can be smarter when it comes to optimizations.

Signed-off-by: Helmut Schaa <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
helmut-jacob authored and blp committed Dec 13, 2013
1 parent e082203 commit 2737b46
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
17 changes: 0 additions & 17 deletions lib/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,6 @@ random_bytes(void *p_, size_t n)
}
}

uint8_t
random_uint8(void)
{
return random_uint32();
}

uint16_t
random_uint16(void)
{
return random_uint32();
}

uint32_t
random_uint32(void)
Expand All @@ -117,12 +106,6 @@ random_uint64(void)
return x;
}

int
random_range(int max)
{
return random_uint32() % max;
}

static uint32_t
random_next(void)
{
Expand Down
21 changes: 18 additions & 3 deletions lib/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,25 @@ void random_init(void);
void random_set_seed(uint32_t);

void random_bytes(void *, size_t);
uint8_t random_uint8(void);
uint16_t random_uint16(void);
uint32_t random_uint32(void);
uint64_t random_uint64(void);
int random_range(int max);

static inline int
random_range(int max)
{
return random_uint32() % max;
}

static inline uint8_t
random_uint8(void)
{
return random_uint32();
}

static inline uint16_t
random_uint16(void)
{
return random_uint32();
}

#endif /* random.h */

0 comments on commit 2737b46

Please sign in to comment.