-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use qsort to sort short ByteString #267
Changes from 1 commit
4b42384
b333cf1
c5c5648
9ade2b0
ab14f68
316f1a3
f3e4d44
81c94b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -75,12 +75,12 @@ module Data.ByteString.Internal ( | |||||
memset, -- :: Ptr Word8 -> Word8 -> CSize -> IO (Ptr Word8) | ||||||
|
||||||
-- * cbits functions | ||||||
c_reverse, -- :: Ptr Word8 -> Ptr Word8 -> CInt -> IO () | ||||||
c_intersperse, -- :: Ptr Word8 -> Ptr Word8 -> CInt -> Word8 -> IO () | ||||||
c_maximum, -- :: Ptr Word8 -> CInt -> IO Word8 | ||||||
c_minimum, -- :: Ptr Word8 -> CInt -> IO Word8 | ||||||
c_count, -- :: Ptr Word8 -> CInt -> Word8 -> IO CInt | ||||||
c_sort, -- :: Ptr Word8 -> CInt -> IO () | ||||||
c_reverse, -- :: Ptr Word8 -> Ptr Word8 -> CSize -> IO () | ||||||
c_intersperse, -- :: Ptr Word8 -> Ptr Word8 -> CSize -> Word8 -> IO () | ||||||
c_maximum, -- :: Ptr Word8 -> CSize -> IO Word8 | ||||||
c_minimum, -- :: Ptr Word8 -> CSize -> IO Word8 | ||||||
c_count, -- :: Ptr Word8 -> CSize -> Word8 -> IO CInt | ||||||
c_sort, -- :: Ptr Word8 -> CSize -> IO () | ||||||
|
||||||
-- * Chars | ||||||
w2c, c2w, isSpaceWord8, isSpaceChar8, | ||||||
|
@@ -746,19 +746,19 @@ memset p w s = c_memset p (fromIntegral w) s | |||||
-- | ||||||
|
||||||
foreign import ccall unsafe "static fpstring.h fps_reverse" c_reverse | ||||||
:: Ptr Word8 -> Ptr Word8 -> CULong -> IO () | ||||||
:: Ptr Word8 -> Ptr Word8 -> CSize -> IO () | ||||||
|
||||||
foreign import ccall unsafe "static fpstring.h fps_intersperse" c_intersperse | ||||||
:: Ptr Word8 -> Ptr Word8 -> CULong -> Word8 -> IO () | ||||||
:: Ptr Word8 -> Ptr Word8 -> CSize -> Word8 -> IO () | ||||||
|
||||||
foreign import ccall unsafe "static fpstring.h fps_maximum" c_maximum | ||||||
:: Ptr Word8 -> CULong -> IO Word8 | ||||||
:: Ptr Word8 -> CSize -> IO Word8 | ||||||
|
||||||
foreign import ccall unsafe "static fpstring.h fps_minimum" c_minimum | ||||||
:: Ptr Word8 -> CULong -> IO Word8 | ||||||
:: Ptr Word8 -> CSize -> IO Word8 | ||||||
|
||||||
foreign import ccall unsafe "static fpstring.h fps_count" c_count | ||||||
:: Ptr Word8 -> CULong -> Word8 -> IO CULong | ||||||
:: Ptr Word8 -> CSize -> Word8 -> IO CULong | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should also return a CSize
Suggested change
|
||||||
|
||||||
foreign import ccall unsafe "static fpstring.h fps_sort" c_sort | ||||||
:: Ptr Word8 -> CULong -> IO () | ||||||
:: Ptr Word8 -> CSize -> IO () |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -32,7 +32,7 @@ | |||||
#include "fpstring.h" | ||||||
|
||||||
/* copy a string in reverse */ | ||||||
void fps_reverse(unsigned char *q, unsigned char *p, unsigned long n) { | ||||||
void fps_reverse(unsigned char *q, unsigned char *p, size_t n) { | ||||||
p += n-1; | ||||||
while (n-- != 0) | ||||||
*q++ = *p--; | ||||||
|
@@ -42,7 +42,7 @@ void fps_reverse(unsigned char *q, unsigned char *p, unsigned long n) { | |||||
of the duplicated string */ | ||||||
void fps_intersperse(unsigned char *q, | ||||||
unsigned char *p, | ||||||
unsigned long n, | ||||||
size_t n, | ||||||
unsigned char c) { | ||||||
|
||||||
while (n > 1) { | ||||||
|
@@ -55,7 +55,7 @@ void fps_intersperse(unsigned char *q, | |||||
} | ||||||
|
||||||
/* find maximum char in a packed string */ | ||||||
unsigned char fps_maximum(unsigned char *p, unsigned long len) { | ||||||
unsigned char fps_maximum(unsigned char *p, size_t len) { | ||||||
unsigned char *q, c = *p; | ||||||
for (q = p; q < p + len; q++) | ||||||
if (*q > c) | ||||||
|
@@ -64,7 +64,7 @@ unsigned char fps_maximum(unsigned char *p, unsigned long len) { | |||||
} | ||||||
|
||||||
/* find minimum char in a packed string */ | ||||||
unsigned char fps_minimum(unsigned char *p, unsigned long len) { | ||||||
unsigned char fps_minimum(unsigned char *p, size_t len) { | ||||||
unsigned char *q, c = *p; | ||||||
for (q = p; q < p + len; q++) | ||||||
if (*q < c) | ||||||
|
@@ -73,7 +73,7 @@ unsigned char fps_minimum(unsigned char *p, unsigned long len) { | |||||
} | ||||||
|
||||||
/* count the number of occurences of a char in a string */ | ||||||
unsigned long fps_count(unsigned char *p, unsigned long len, unsigned char w) { | ||||||
unsigned long fps_count(unsigned char *p, size_t len, unsigned char w) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
And also in the declartion of |
||||||
unsigned long c; | ||||||
for (c = 0; len-- != 0; ++p) | ||||||
if (*p == w) | ||||||
|
@@ -93,6 +93,6 @@ int fps_compare(const void *a, const void *b) { | |||||
return (int)*(unsigned char*)a - (int)*(unsigned char*)b; | ||||||
} | ||||||
|
||||||
void fps_sort(unsigned char *p, unsigned long len) { | ||||||
void fps_sort(unsigned char *p, size_t len) { | ||||||
return qsort(p, len, 1, fps_compare); | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,11 +1,9 @@ | ||||||
|
||||||
#include <string.h> | ||||||
#include <stdlib.h> | ||||||
|
||||||
void fps_reverse(unsigned char *dest, unsigned char *from, unsigned long len); | ||||||
void fps_intersperse(unsigned char *dest, unsigned char *from, unsigned long len, unsigned char c); | ||||||
unsigned char fps_maximum(unsigned char *p, unsigned long len); | ||||||
unsigned char fps_minimum(unsigned char *p, unsigned long len); | ||||||
unsigned long fps_count(unsigned char *p, unsigned long len, unsigned char w); | ||||||
void fps_sort(unsigned char *p, unsigned long len); | ||||||
|
||||||
void fps_reverse(unsigned char *dest, unsigned char *from, size_t len); | ||||||
void fps_intersperse(unsigned char *dest, unsigned char *from, size_t len, unsigned char c); | ||||||
unsigned char fps_maximum(unsigned char *p, size_t len); | ||||||
unsigned char fps_minimum(unsigned char *p, size_t len); | ||||||
unsigned long fps_count(unsigned char *p, size_t len, unsigned char w); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
void fps_sort(unsigned char *p, size_t len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could affect all sites that don't use
fromIntegral
, but that's probably already handled, becauseCInt
isn't a priori any particular one of the normal Haskell integral types, so thefromIntegral
should already be there.