home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.4 / 7.4.351 < prev    next >
Encoding:
Internet Message Format  |  2014-07-01  |  5.9 KB

  1. To: vim_dev@googlegroups.com
  2. Subject: Patch 7.4.351
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.4.351
  11. Problem:    sort() is not stable.
  12. Solution:   When the items are identical, compare the pointers.
  13. Files:        src/eval.c, src/testdir/test55.in, src/testdir/test55.ok
  14.  
  15.  
  16. *** ../vim-7.4.350/src/eval.c    2014-06-25 17:31:04.942737863 +0200
  17. --- src/eval.c    2014-07-02 18:52:19.102313288 +0200
  18. ***************
  19. *** 17334,17339 ****
  20. --- 17334,17340 ----
  21.   static char_u    *item_compare_func;
  22.   static dict_T    *item_compare_selfdict;
  23.   static int    item_compare_func_err;
  24. + static int    item_compare_keep_zero;
  25.   static void    do_sort_uniq __ARGS((typval_T *argvars, typval_T *rettv, int sort));
  26.   #define ITEM_COMPARE_FAIL 999
  27.   
  28. ***************
  29. *** 17374,17379 ****
  30. --- 17375,17386 ----
  31.       n2 = strtod((char *)p2, (char **)&p2);
  32.       res = n1 == n2 ? 0 : n1 > n2 ? 1 : -1;
  33.       }
  34. +     /* When the result would be zero, compare the pointers themselves.  Makes
  35. +      * the sort stable. */
  36. +     if (res == 0 && !item_compare_keep_zero)
  37. +     res = s1 > s2 ? 1 : -1;
  38.       vim_free(tofree1);
  39.       vim_free(tofree2);
  40.       return res;
  41. ***************
  42. *** 17396,17402 ****
  43.       if (item_compare_func_err)
  44.       return 0;
  45.   
  46. !     /* copy the values.  This is needed to be able to set v_lock to VAR_FIXED
  47.        * in the copy without changing the original list items. */
  48.       copy_tv(&(*(listitem_T **)s1)->li_tv, &argv[0]);
  49.       copy_tv(&(*(listitem_T **)s2)->li_tv, &argv[1]);
  50. --- 17403,17409 ----
  51.       if (item_compare_func_err)
  52.       return 0;
  53.   
  54. !     /* Copy the values.  This is needed to be able to set v_lock to VAR_FIXED
  55.        * in the copy without changing the original list items. */
  56.       copy_tv(&(*(listitem_T **)s1)->li_tv, &argv[0]);
  57.       copy_tv(&(*(listitem_T **)s2)->li_tv, &argv[1]);
  58. ***************
  59. *** 17415,17420 ****
  60. --- 17422,17433 ----
  61.       if (item_compare_func_err)
  62.       res = ITEM_COMPARE_FAIL;  /* return value has wrong type */
  63.       clear_tv(&rettv);
  64. +     /* When the result would be zero, compare the pointers themselves.  Makes
  65. +      * the sort stable. */
  66. +     if (res == 0 && !item_compare_keep_zero)
  67. +     res = s1 > s2 ? 1 : -1;
  68.       return res;
  69.   }
  70.   
  71. ***************
  72. *** 17509,17514 ****
  73. --- 17522,17528 ----
  74.           ptrs[i++] = li;
  75.   
  76.           item_compare_func_err = FALSE;
  77. +         item_compare_keep_zero = FALSE;
  78.           /* test the compare function */
  79.           if (item_compare_func != NULL
  80.               && item_compare2((void *)&ptrs[0], (void *)&ptrs[1])
  81. ***************
  82. *** 17536,17541 ****
  83. --- 17550,17556 ----
  84.   
  85.           /* f_uniq(): ptrs will be a stack of items to remove */
  86.           item_compare_func_err = FALSE;
  87. +         item_compare_keep_zero = TRUE;
  88.           item_compare_func_ptr = item_compare_func
  89.                              ? item_compare2 : item_compare;
  90.   
  91. *** ../vim-7.4.350/src/testdir/test55.in    2014-06-26 22:33:47.850693627 +0200
  92. --- src/testdir/test55.in    2014-07-02 19:00:09.238320492 +0200
  93. ***************
  94. *** 332,340 ****
  95.   :$put =string(reverse(sort(l)))
  96.   :$put =string(sort(reverse(sort(l))))
  97.   :$put =string(uniq(sort(l)))
  98. ! :let l=[7, 9, 18, 12, 22, 10.0e-16, -1, 0xff, 0.22, 'foo']
  99.   :$put =string(sort(copy(l), 'n'))
  100. ! :let l=[7, 9, 18, 12, 22, 10.0e-16, -1, 0xff, 0, -0, 0.22, 'foo', 'FOOBAR',{}, []]
  101.   :$put =string(sort(copy(l), 1))
  102.   :$put =string(sort(copy(l), 'i'))
  103.   :$put =string(sort(copy(l)))
  104. --- 332,340 ----
  105.   :$put =string(reverse(sort(l)))
  106.   :$put =string(sort(reverse(sort(l))))
  107.   :$put =string(uniq(sort(l)))
  108. ! :let l=[7, 9, 'one', 18, 12, 22, 'two', 10.0e-16, -1, 'three', 0xff, 0.22, 'four']
  109.   :$put =string(sort(copy(l), 'n'))
  110. ! :let l=[7, 9, 18, 12, 22, 10.0e-16, -1, 0xff, 0, -0, 0.22, 'bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', {}, []]
  111.   :$put =string(sort(copy(l), 1))
  112.   :$put =string(sort(copy(l), 'i'))
  113.   :$put =string(sort(copy(l)))
  114. *** ../vim-7.4.350/src/testdir/test55.ok    2014-06-26 22:33:47.850693627 +0200
  115. --- src/testdir/test55.ok    2014-07-02 19:00:57.078321225 +0200
  116. ***************
  117. *** 101,110 ****
  118.   [[0, 1, 2], [0, 1, 2], 4, 2, 2, 1.5, 'xaaa', 'x8', 'foo6', 'foo', 'foo', 'A11', '-0']
  119.   ['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]]
  120.   ['-0', 'A11', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 4, [0, 1, 2]]
  121. ! [-1, 'foo', 1.0e-15, 0.22, 7, 9, 12, 18, 22, 255]
  122. ! ['foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}]
  123. ! ['foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}]
  124. ! ['FOOBAR', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}]
  125.   ['aa', 'bb']
  126.   ['aa', 'bb']
  127.   ['', 'aa', 'bb', '']
  128. --- 101,110 ----
  129.   [[0, 1, 2], [0, 1, 2], 4, 2, 2, 1.5, 'xaaa', 'x8', 'foo6', 'foo', 'foo', 'A11', '-0']
  130.   ['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]]
  131.   ['-0', 'A11', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 4, [0, 1, 2]]
  132. ! [-1, 'one', 'two', 'three', 'four', 1.0e-15, 0.22, 7, 9, 12, 18, 22, 255]
  133. ! ['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}]
  134. ! ['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}]
  135. ! ['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}]
  136.   ['aa', 'bb']
  137.   ['aa', 'bb']
  138.   ['', 'aa', 'bb', '']
  139. *** ../vim-7.4.350/src/version.c    2014-07-02 18:27:44.662290695 +0200
  140. --- src/version.c    2014-07-02 18:46:38.230308065 +0200
  141. ***************
  142. *** 736,737 ****
  143. --- 736,739 ----
  144.   {   /* Add new patch number below this line */
  145. + /**/
  146. +     351,
  147.   /**/
  148.  
  149. -- 
  150. The early bird gets the worm. If you want something else for
  151. breakfast, get up later.
  152.  
  153.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  154. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  155. \\\  an exciting new programming language -- http://www.Zimbu.org        ///
  156.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  157.