1
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
3
This library is free software; you can redistribute it and/or
4
modify it under the terms of the GNU Library General Public
5
License as published by the Free Software Foundation; either
6
version 2 of the License, or (at your option) any later version.
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public
14
License along with this library; if not, write to the Free
15
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19
get_ptr_compare(len) returns a pointer to a optimal byte-compare function
20
for a array of stringpointer where all strings have size len.
21
The bytes are compare as unsigned chars.
22
Because the size is saved in a static variable.
23
When using threads the program must have called my_init and the thread
27
#include "mysys_priv.h"
29
static int ptr_compare(uint *compare_length, uchar **a, uchar **b);
30
static int ptr_compare_0(uint *compare_length, uchar **a, uchar **b);
31
static int ptr_compare_1(uint *compare_length, uchar **a, uchar **b);
32
static int ptr_compare_2(uint *compare_length, uchar **a, uchar **b);
33
static int ptr_compare_3(uint *compare_length, uchar **a, uchar **b);
35
/* Get a pointer to a optimal byte-compare function for a given size */
37
qsort2_cmp get_ptr_compare (uint size)
40
return (qsort2_cmp) ptr_compare;
42
case 0: return (qsort2_cmp) ptr_compare_0;
43
case 1: return (qsort2_cmp) ptr_compare_1;
44
case 2: return (qsort2_cmp) ptr_compare_2;
45
case 3: return (qsort2_cmp) ptr_compare_3;
47
return 0; /* Impossible */
52
Compare to keys to see witch is smaller.
53
Loop unrolled to make it quick !!
56
#define cmp(N) if (first[N] != last[N]) return (int) first[N] - (int) last[N]
58
static int ptr_compare(uint *compare_length, uchar **a, uchar **b)
60
reg3 int length= *compare_length;
61
reg1 uchar *first,*last;
66
if (*first++ != *last++)
67
return (int) first[-1] - (int) last[-1];
69
return (int) first[0] - (int) last[0];
73
static int ptr_compare_0(uint *compare_length,uchar **a, uchar **b)
75
reg3 int length= *compare_length;
76
reg1 uchar *first,*last;
94
static int ptr_compare_1(uint *compare_length,uchar **a, uchar **b)
96
reg3 int length= *compare_length-1;
97
reg1 uchar *first,*last;
99
first= *a+1; last= *b+1;
115
static int ptr_compare_2(uint *compare_length,uchar **a, uchar **b)
117
reg3 int length= *compare_length-2;
118
reg1 uchar *first,*last;
120
first= *a +2 ; last= *b +2;
137
static int ptr_compare_3(uint *compare_length,uchar **a, uchar **b)
139
reg3 int length= *compare_length-3;
140
reg1 uchar *first,*last;
142
first= *a +3 ; last= *b +3;