|
1 |
| -/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. |
| 1 | +/* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 2 |
|
3 | 3 | This program is free software; you can redistribute it and/or modify
|
4 | 4 | it under the terms of the GNU General Public License as published by
|
|
18 | 18 | them in sorted order through SORT_INFO functions.
|
19 | 19 | */
|
20 | 20 |
|
| 21 | +#include <algorithm> |
| 22 | +#include <functional> |
| 23 | +#include <my_global.h> |
21 | 24 | #include "fulltext.h"
|
22 | 25 | #if defined(__WIN__)
|
23 | 26 | #include <fcntl.h>
|
|
36 | 39 | #define MYF_RW MYF(MY_NABP | MY_WME | MY_WAIT_IF_FULL)
|
37 | 40 | #define DISK_BUFFER_SIZE (IO_SIZE*16)
|
38 | 41 |
|
| 42 | +class Key_compare : |
| 43 | + public std::binary_function<const uchar*, const uchar*, bool> |
| 44 | +{ |
| 45 | +public: |
| 46 | + Key_compare(MI_SORT_PARAM *param) : info(param) {} |
| 47 | + bool operator()(const uchar *a, const uchar *b) |
| 48 | + { |
| 49 | + return info->key_cmp(info, &a, &b) < 0; |
| 50 | + } |
| 51 | + MI_SORT_PARAM *info; |
| 52 | +}; |
39 | 53 |
|
40 | 54 | /*
|
41 | 55 | Pointers of functions for store and read keys from temp file
|
@@ -568,7 +582,7 @@ int thr_write_keys(MI_SORT_PARAM *sort_param)
|
568 | 582 | length=param->sort_buffer_length;
|
569 | 583 | while (length >= MIN_SORT_BUFFER)
|
570 | 584 | {
|
571 |
| - if ((mergebuf= my_malloc(length, MYF(0)))) |
| 585 | + if ((mergebuf= (uchar *) my_malloc(length, MYF(0)))) |
572 | 586 | break;
|
573 | 587 | length=length*3/4;
|
574 | 588 | }
|
@@ -655,8 +669,8 @@ static int write_keys(MI_SORT_PARAM *info, register uchar **sort_keys,
|
655 | 669 | uint sort_length=info->key_length;
|
656 | 670 | DBUG_ENTER("write_keys");
|
657 | 671 |
|
658 |
| - my_qsort2((uchar*) sort_keys,count,sizeof(uchar*),(qsort2_cmp) info->key_cmp, |
659 |
| - info); |
| 672 | + std::sort(sort_keys, sort_keys + count, Key_compare(info)); |
| 673 | + |
660 | 674 | if (!my_b_inited(tempfile) &&
|
661 | 675 | open_cached_file(tempfile, my_tmpdir(info->tmpdir), "ST",
|
662 | 676 | DISK_BUFFER_SIZE, info->sort_info->param->myf_rw))
|
@@ -698,8 +712,8 @@ static int write_keys_varlen(MI_SORT_PARAM *info,
|
698 | 712 | int err;
|
699 | 713 | DBUG_ENTER("write_keys_varlen");
|
700 | 714 |
|
701 |
| - my_qsort2((uchar*) sort_keys,count,sizeof(uchar*),(qsort2_cmp) info->key_cmp, |
702 |
| - info); |
| 715 | + std::sort(sort_keys, sort_keys + count, Key_compare(info)); |
| 716 | + |
703 | 717 | if (!my_b_inited(tempfile) &&
|
704 | 718 | open_cached_file(tempfile, my_tmpdir(info->tmpdir), "ST",
|
705 | 719 | DISK_BUFFER_SIZE, info->sort_info->param->myf_rw))
|
@@ -740,8 +754,8 @@ static int write_index(MI_SORT_PARAM *info, register uchar **sort_keys,
|
740 | 754 | {
|
741 | 755 | DBUG_ENTER("write_index");
|
742 | 756 |
|
743 |
| - my_qsort2((uchar*) sort_keys,(size_t) count,sizeof(uchar*), |
744 |
| - (qsort2_cmp) info->key_cmp,info); |
| 757 | + std::sort(sort_keys, sort_keys + count, Key_compare(info)); |
| 758 | + |
745 | 759 | while (count--)
|
746 | 760 | {
|
747 | 761 | if ((*info->key_write)(info,*sort_keys++))
|
|
0 commit comments