Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
0f05f0fc
Commit
0f05f0fc
authored
Feb 01, 2016
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize qa_sort_by
Avoid extra comparison function.
parent
4f8dc92b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
4 deletions
+15
-4
sort.php
qa-include/util/sort.php
+15
-4
No files found.
qa-include/util/sort.php
View file @
0f05f0fc
...
...
@@ -46,16 +46,27 @@ function qa_sort_by_fn($a, $b)
{
global
$qa_sort_by_1
,
$qa_sort_by_2
;
$compare
=
qa_sort_cmp
(
$a
[
$qa_sort_by_1
],
$b
[
$qa_sort_by_1
]);
// if the first keys are equal we can sort by the second keys only
$sortkey
=
$qa_sort_by_1
;
if
(
$a
[
$sortkey
]
==
$b
[
$sortkey
])
{
if
(
!
isset
(
$qa_sort_by_2
))
return
0
;
if
(
$compare
==
0
&&
$qa_sort_by_2
)
$compare
=
qa_sort_cmp
(
$a
[
$qa_sort_by_2
],
$b
[
$qa_sort_by_2
]);
$sortkey
=
$qa_sort_by_2
;
}
$av
=
$a
[
$sortkey
];
$bv
=
$b
[
$sortkey
];
return
$compare
;
if
(
is_numeric
(
$av
)
&&
is_numeric
(
$bv
))
// straight subtraction won't work for floating bits
return
$av
==
$bv
?
0
:
(
$av
<
$bv
?
-
1
:
1
);
else
return
strcasecmp
(
$av
,
$bv
);
// doesn't do UTF-8 right but it will do for now
}
/**
* General comparison function for two values, textual or numeric
* @deprecated
*/
function
qa_sort_cmp
(
$a
,
$b
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment