memcpy(d, s, len);
}
+/* copies <len> bytes from <src> to <dst>, converting upper case characters to
+ * lower case ones. Nothing else is changed. It's expected to be used inlined
+ * inside other functions operating on short strings (handles one char at a
+ * time. It is designed this way to permit the compiler to vectorize it when
+ * it makes sense (easy via cmp/mask/sub since len is known). NUL chars are
+ * properly copied and none is appended.
+ */
+static forceinline void memlower(void *dst, const void *src, size_t len)
+{
+ const uchar *_src = src;
+ uchar *_dst = dst;
+ size_t i;
+
+ for (i = 0; i < len; i++) {
+ if ((_src[i] >= 'A') && (_src[i] <= 'Z'))
+ _dst[i] = _src[i] + 'a' - 'A';
+ else
+ _dst[i] = _src[i];
+ }
+}
+
+/* copies <len> bytes from <src> to <dst>, converting lower case characters to
+ * upper case ones. Nothing else is changed. It's expected to be used inlined
+ * inside other functions operating on short strings (handles one char at a
+ * time. It is designed this way to permit the compiler to vectorize it when
+ * it makes sense (easy via cmp/mask/sub since len is known). NUL chars are
+ * properly copied and none is appended.
+ */
+static forceinline void memupper(void *dst, const void *src, size_t len)
+{
+ const uchar *_src = src;
+ uchar *_dst = dst;
+ size_t i;
+
+ for (i = 0; i < len; i++) {
+ if ((_src[i] >= 'a') && (_src[i] <= 'z'))
+ _dst[i] = _src[i] + 'A' - 'a';
+ else
+ _dst[i] = _src[i];
+ }
+}
+
/* This function returns the first unused key greater than or equal to <key> in
* ID tree <root>. Zero is returned if no place is found.
*/
static int sample_conv_str2lower(const struct arg *arg_p, struct sample *smp, void *private)
{
const char *src = smp->data.u.str.area;
- char *dst;
- int i;
- /* <dst> may alias <src>, we never write ahead of where we read */
+ /* output sample may alias <src>, we never write ahead of where we read */
if (!smp_prepare_out(smp))
return 0;
- dst = smp->data.u.str.area;
- for (i = 0; i < smp->data.u.str.data; i++) {
- if ((src[i] >= 'A') && (src[i] <= 'Z'))
- dst[i] = src[i] + 'a' - 'A';
- else
- dst[i] = src[i];
- }
+ memlower(smp->data.u.str.area, src, smp->data.u.str.data);
return 1;
}
static int sample_conv_str2upper(const struct arg *arg_p, struct sample *smp, void *private)
{
const char *src = smp->data.u.str.area;
- char *dst;
- int i;
- /* <dst> may alias <src>, we never write ahead of where we read */
+ /* output sample may alias <src>, we never write ahead of where we read */
if (!smp_prepare_out(smp))
return 0;
- dst = smp->data.u.str.area;
- for (i = 0; i < smp->data.u.str.data; i++) {
- if ((src[i] >= 'a') && (src[i] <= 'z'))
- dst[i] = src[i] + 'A' - 'a';
- else
- dst[i] = src[i];
- }
+ memupper(smp->data.u.str.area, src, smp->data.u.str.data);
return 1;
}