diff options
Diffstat (limited to 'src/svnqt/client_impl.cpp')
-rw-r--r-- | src/svnqt/client_impl.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/svnqt/client_impl.cpp b/src/svnqt/client_impl.cpp index 736afca..d138016 100644 --- a/src/svnqt/client_impl.cpp +++ b/src/svnqt/client_impl.cpp @@ -38,6 +38,51 @@ #include <tqmap.h> #include <tqstringlist.h> + +#if (!(SVN_VER_MAJOR == 1 && SVN_VER_MINOR <= 8)) +apr_array_header_t* svn_sort__hash(apr_hash_t *ht, + int (*comparison_func)(const svn_sort__item_t*, const svn_sort__item_t*), apr_pool_t *pool) +{ + apr_hash_index_t *hi; + apr_array_header_t *ary; + svn_boolean_t sorted; + svn_sort_item_type *prev_item; + + /* allocate an array with enough elements to hold all the keys. */ + ary = apr_array_make(pool, apr_hash_count(ht), sizeof(svn_sort_item_type)); + + /* loop over hash table and push all keys into the array */ + sorted = TRUE; + prev_item = NULL; + for (hi = apr_hash_first(pool, ht); hi; hi = apr_hash_next(hi)) + { + svn_sort_item_type *item = (svn_sort_item_type*)apr_array_push(ary); + apr_hash_this(hi, &item->key, &item->klen, &item->value); + + if (prev_item == NULL) + { + prev_item = item; + continue; + } + + if (sorted) + { + sorted = (comparison_func((svn_sort__item_t*)prev_item, (svn_sort__item_t*)item) < 0); + prev_item = item; + } + } + + /* quicksort the array if it isn't already sorted. */ + if (!sorted) + { + qsort(ary->elts, ary->nelts, ary->elt_size, + (int (*)(const void*, const void*))comparison_func); + } + + return ary; +} +#endif + namespace svn { |