1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-8360 Clean-up CHARSET_INFO: strnncollsp: diff_if_only_endspace_difference

- Removing the "diff_if_only_endspace_difference" argument from
  MY_COLLATION_HANDLER::strnncollsp(), my_strnncollsp_simple(),
  as well as in the function template MY_FUNCTION_NAME(strnncollsp)
  in strcoll.ic

- Removing the "diff_if_only_space_different" from ha_compare_text(),
  hp_rec_key_cmp().

- Adding a new function my_strnncollsp_padspace_bin() and reusing
  it instead of duplicate code pieces in my_strnncollsp_8bit_bin(),
  my_strnncollsp_latin1_de(), my_strnncollsp_tis620(),
  my_strnncollsp_utf8_cs().

- Adding more tests for better coverage of the trailing space handling.

- Removing the unused definition of HA_END_SPACE_ARE_EQUAL
This commit is contained in:
Alexander Barkov
2016-03-31 11:04:48 +04:00
parent 282497dd6d
commit 1d73005bf3
58 changed files with 312 additions and 332 deletions

View File

@ -119,9 +119,7 @@ size_t my_lengthsp_binary(CHARSET_INFO *cs __attribute__((unused)),
static int my_strnncollsp_binary(CHARSET_INFO * cs __attribute__((unused)),
const uchar *s, size_t slen,
const uchar *t, size_t tlen,
my_bool diff_if_only_endspace_difference
__attribute__((unused)))
const uchar *t, size_t tlen)
{
return my_strnncoll_binary(cs,s,slen,t,tlen,0);
}
@ -138,6 +136,27 @@ static int my_strnncoll_8bit_bin(CHARSET_INFO * cs __attribute__((unused)),
}
/*
Compare a string to an array of spaces, for PAD SPACE behaviour.
@param str - the string
@param length - the length of the string
@return <0 - if a byte less than SPACE was found
@return >0 - if a byte greater than SPACE was found
@return 0 - if the string entirely consists of SPACE characters
*/
int my_strnncollsp_padspace_bin(const uchar *str, size_t length)
{
for ( ; length ; str++, length--)
{
if (*str < ' ')
return -1;
else if (*str > ' ')
return 1;
}
return 0;
}
/*
Compare two strings. Result is sign(first_argument - second_argument)
@ -148,9 +167,6 @@ static int my_strnncoll_8bit_bin(CHARSET_INFO * cs __attribute__((unused)),
slen Length of 's'
t String to compare
tlen Length of 't'
diff_if_only_endspace_difference
Set to 1 if the strings should be regarded as different
if they only difference in end space
NOTE
This function is used for character strings with binary collations.
@ -165,16 +181,10 @@ static int my_strnncoll_8bit_bin(CHARSET_INFO * cs __attribute__((unused)),
static int my_strnncollsp_8bit_bin(CHARSET_INFO * cs __attribute__((unused)),
const uchar *a, size_t a_length,
const uchar *b, size_t b_length,
my_bool diff_if_only_endspace_difference)
const uchar *b, size_t b_length)
{
const uchar *end;
size_t length;
int res;
#ifndef VARCHAR_WITH_DIFF_ENDSPACE_ARE_DIFFERENT_FOR_UNIQUE
diff_if_only_endspace_difference= 0;
#endif
end= a + (length= MY_MIN(a_length, b_length));
while (a < end)
@ -182,31 +192,10 @@ static int my_strnncollsp_8bit_bin(CHARSET_INFO * cs __attribute__((unused)),
if (*a++ != *b++)
return ((int) a[-1] - (int) b[-1]);
}
res= 0;
if (a_length != b_length)
{
int swap= 1;
/*
Check the next not space character of the longer key. If it's < ' ',
then it's smaller than the other key.
*/
if (diff_if_only_endspace_difference)
res= 1; /* Assume 'a' is bigger */
if (a_length < b_length)
{
/* put shorter key in s */
a_length= b_length;
a= b;
swap= -1; /* swap sign of result */
res= -res;
}
for (end= a + a_length-length; a < end ; a++)
{
if (*a != ' ')
return (*a < ' ') ? -swap : swap;
}
}
return res;
return a_length == b_length ? 0 :
a_length < b_length ?
-my_strnncollsp_padspace_bin(b, b_length - length) :
my_strnncollsp_padspace_bin(a, a_length - length);
}