| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#define PERL_NO_GET_CONTEXT |
|
2
|
|
|
|
|
|
|
#include "locale.h" |
|
3
|
|
|
|
|
|
|
#include "EXTERN.h" |
|
4
|
|
|
|
|
|
|
#include "perl.h" |
|
5
|
|
|
|
|
|
|
#include "XSUB.h" |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#include "ppport.h" |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#include "src/nsort.h" |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#include "const-c.inc" |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
static I32 |
|
14
|
1270
|
|
|
|
|
|
S_sv_ncmp(pTHX_ SV *a, SV *b) |
|
15
|
|
|
|
|
|
|
{ |
|
16
|
1270
|
50
|
|
|
|
|
const char *ia = (const char *) SvPVbyte_nolen(a); |
|
17
|
1270
|
50
|
|
|
|
|
const char *ib = (const char *) SvPVbyte_nolen(b); |
|
18
|
1270
|
|
|
|
|
|
return _ncmp(ia, ib, 0, 0); |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
static I32 |
|
22
|
9
|
|
|
|
|
|
S_sv_ncmp_reverse(pTHX_ SV *a, SV *b) |
|
23
|
|
|
|
|
|
|
{ |
|
24
|
9
|
50
|
|
|
|
|
const char *ia = (const char *) SvPVbyte_nolen(a); |
|
25
|
9
|
50
|
|
|
|
|
const char *ib = (const char *) SvPVbyte_nolen(b); |
|
26
|
9
|
|
|
|
|
|
return _ncmp(ia, ib, 1, 0); |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
static I32 |
|
30
|
0
|
|
|
|
|
|
S_sv_ncoll(pTHX_ SV *a, SV *b) |
|
31
|
|
|
|
|
|
|
{ |
|
32
|
0
|
0
|
|
|
|
|
const char *ia = (const char *) SvPVbyte_nolen(a); |
|
33
|
0
|
0
|
|
|
|
|
const char *ib = (const char *) SvPVbyte_nolen(b); |
|
34
|
0
|
|
|
|
|
|
return _ncmp(ia, ib, 0, 1); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
static I32 |
|
38
|
0
|
|
|
|
|
|
S_sv_ncoll_reverse(pTHX_ SV *a, SV *b) |
|
39
|
|
|
|
|
|
|
{ |
|
40
|
0
|
0
|
|
|
|
|
const char *ia = (const char *) SvPVbyte_nolen(a); |
|
41
|
0
|
0
|
|
|
|
|
const char *ib = (const char *) SvPVbyte_nolen(b); |
|
42
|
0
|
|
|
|
|
|
return _ncmp(ia, ib, 1, 1); |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
MODULE = Sort::Naturally::XS PACKAGE = Sort::Naturally::XS |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
INCLUDE: const-xs.inc |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
int |
|
50
|
|
|
|
|
|
|
ncmp(arg_a, arg_b) |
|
51
|
|
|
|
|
|
|
const char * arg_a |
|
52
|
|
|
|
|
|
|
const char * arg_b |
|
53
|
|
|
|
|
|
|
CODE: |
|
54
|
689
|
|
|
|
|
|
RETVAL = _ncmp(arg_a, arg_b, 0, 0); |
|
55
|
|
|
|
|
|
|
OUTPUT: |
|
56
|
|
|
|
|
|
|
RETVAL |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
void |
|
59
|
|
|
|
|
|
|
nsort(...) |
|
60
|
|
|
|
|
|
|
PROTOTYPE: @ |
|
61
|
|
|
|
|
|
|
CODE: |
|
62
|
8
|
50
|
|
|
|
|
if (!items) { |
|
63
|
0
|
|
|
|
|
|
XSRETURN_UNDEF; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
8
|
|
|
|
|
|
AV * array = newAV(); |
|
66
|
|
|
|
|
|
|
int i; |
|
67
|
198
|
100
|
|
|
|
|
for (i=0; i
|
|
68
|
190
|
|
|
|
|
|
av_push(array, ST(i)); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
8
|
|
|
|
|
|
sortsv(AvARRAY(array), items, S_sv_ncmp); |
|
71
|
198
|
100
|
|
|
|
|
for (i=0; i
|
|
72
|
190
|
|
|
|
|
|
ST(i) = av_shift(array); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
8
|
|
|
|
|
|
av_undef(array); |
|
75
|
8
|
|
|
|
|
|
SvREFCNT_dec(array); |
|
76
|
8
|
|
|
|
|
|
XSRETURN(items); |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
void |
|
79
|
|
|
|
|
|
|
_sorted(array_ref, reverse, locale) |
|
80
|
|
|
|
|
|
|
SV * array_ref |
|
81
|
|
|
|
|
|
|
int reverse |
|
82
|
|
|
|
|
|
|
const char * locale |
|
83
|
|
|
|
|
|
|
CODE: |
|
84
|
9
|
50
|
|
|
|
|
if (!SvROK(array_ref) || SvTYPE(SvRV(array_ref)) != SVt_PVAV) { |
|
|
|
50
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
croak("Not an ARRAY ref"); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
9
|
|
|
|
|
|
AV * array = (AV *) SvRV(array_ref); |
|
88
|
9
|
|
|
|
|
|
int array_len = av_len(array) + 1; |
|
89
|
9
|
50
|
|
|
|
|
if (locale != NULL && strlen(locale)) { |
|
|
|
50
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
const char * old_locale = setlocale(LC_ALL, locale); |
|
91
|
0
|
0
|
|
|
|
|
if (reverse) { |
|
92
|
0
|
|
|
|
|
|
sortsv(AvARRAY(array), array_len, S_sv_ncoll_reverse); |
|
93
|
|
|
|
|
|
|
} else { |
|
94
|
0
|
|
|
|
|
|
sortsv(AvARRAY(array), array_len, S_sv_ncoll); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
0
|
|
|
|
|
|
setlocale(LC_ALL, old_locale); |
|
97
|
|
|
|
|
|
|
} else { |
|
98
|
9
|
100
|
|
|
|
|
if (reverse) { |
|
99
|
1
|
|
|
|
|
|
sortsv(AvARRAY(array), array_len, S_sv_ncmp_reverse); |
|
100
|
|
|
|
|
|
|
} else { |
|
101
|
8
|
|
|
|
|
|
sortsv(AvARRAY(array), array_len, S_sv_ncmp); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
} |