136
125
MAX_DECPT_FOR_F_FORMAT zeros for cases when |x|<1 and the 'f' format is used).
138
127
#define MY_GCVT_MAX_FIELD_WIDTH (DBL_DIG + 4 + cmax(5, MAX_DECPT_FOR_F_FORMAT))
141
130
extern char *llstr(int64_t value,char *buff);
142
131
extern char *ullstr(int64_t value,char *buff);
144
extern char *int2str(long val, char *dst, int radix, int upcase);
145
extern char *int10_to_str(long val,char *dst,int radix);
133
extern char *int2str(int32_t val, char *dst, int radix, int upcase);
134
extern char *int10_to_str(int32_t val,char *dst,int radix);
146
135
extern char *str2int(const char *src,int radix,long lower,long upper,
148
137
int64_t my_strtoll10(const char *nptr, char **endptr, int *error);
149
#if SIZEOF_LONG == SIZEOF_LONG_LONG
150
#define int64_t2str(A,B,C) int2str((A),(B),(C),1)
151
#define int64_t10_to_str(A,B,C) int10_to_str((A),(B),(C))
153
138
extern char *int64_t2str(int64_t val,char *dst,int radix);
154
139
extern char *int64_t10_to_str(int64_t val,char *dst,int radix);
158
142
#if defined(__cplusplus)
163
LEX_STRING -- a pair of a C-string and its length.
167
/* This definition must match the one given in mysql/plugin.h */
168
struct st_mysql_lex_string
174
typedef struct st_mysql_lex_string LEX_STRING;
176
#define STRING_WITH_LEN(X) (X), ((size_t) (sizeof(X) - 1))
177
#define USTRING_WITH_LEN(X) ((unsigned char*) X), ((size_t) (sizeof(X) - 1))
178
#define C_STRING_WITH_LEN(X) ((char *) (X)), ((size_t) (sizeof(X) - 1))
180
/* SPACE_INT is a word that contains only spaces */
182
#define SPACE_INT 0x20202020
183
#elif SIZEOF_INT == 8
184
#define SPACE_INT 0x2020202020202020
186
#error define the appropriate constant for a word full of spaces
190
148
Skip trailing space.
192
On most systems reading memory in larger chunks (ideally equal to the size of
193
the chinks that the machine physically reads from memory) causes fewer memory
194
access loops and hence increased performance.
195
This is why the 'int' type is used : it's closest to that (according to how
197
So when we determine the amount of whitespace at the end of a string we do
199
1. We divide the string into 3 zones :
200
a) from the start of the string (__start) to the first multiple
201
of sizeof(int) (__start_words)
202
b) from the end of the string (__end) to the last multiple of sizeof(int)
204
c) a zone that is aligned to sizeof(int) and can be safely accessed
206
2. We start comparing backwards from (c) char-by-char. If all we find is
207
space then we continue
208
3. If there are elements in zone (b) we compare them as unsigned ints to a
209
int mask (SPACE_INT) consisting of all spaces
210
4. Finally we compare the remaining part (a) of the string char by char.
211
This covers for the last non-space unsigned int from 3. (if any)
213
This algorithm works well for relatively larger strings, but it will slow
214
the things down for smaller strings (because of the additional calculations
215
and checks compared to the naive method). Thus the barrier of length 20
218
150
@param ptr pointer to the input string
219
151
@param len the length of the string
220
152
@return the last non-space character
223
static inline const unsigned char *skip_trailing_space(const unsigned char *ptr,size_t len)
155
static inline const unsigned char *
156
skip_trailing_space(const unsigned char *ptr, size_t len)
225
158
const unsigned char *end= ptr + len;
229
const unsigned char *end_words= (const unsigned char *)(intptr_t)
230
(((uint64_t)(intptr_t)end) / SIZEOF_INT * SIZEOF_INT);
231
const unsigned char *start_words= (const unsigned char *)(intptr_t)
232
((((uint64_t)(intptr_t)ptr) + SIZEOF_INT - 1) / SIZEOF_INT * SIZEOF_INT);
234
assert(((uint64_t)(intptr_t)ptr) >= SIZEOF_INT);
237
while (end > end_words && end[-1] == 0x20)
239
if (end[-1] == 0x20 && start_words < end_words)
240
while (end > start_words && ((const unsigned *)end)[-1] == SPACE_INT)
244
while (end > ptr && end[-1] == 0x20)
160
while (end > ptr && isspace(*--end))