Created
January 12, 2012 10:15
-
-
Save koron/1599706 to your computer and use it in GitHub Desktop.
Rev.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # HG changeset patch | |
| # Parent 2cab0b1a3f2992429db480acd43d852a4c85d95e | |
| diff -r 2cab0b1a3f29 src/eval.c | |
| --- a/src/eval.c Wed Jan 11 18:57:32 2012 +0900 | |
| +++ b/src/eval.c Thu Jan 12 22:04:03 2012 +0900 | |
| @@ -6572,6 +6572,66 @@ | |
| return (char_u *)ga.ga_data; | |
| } | |
| + static int | |
| +list_join2(gap, l, sep, echo_style, copyID, gap2) | |
| + garray_T *gap; | |
| + list_T *l; | |
| + char_u *sep; | |
| + int echo_style; | |
| + int copyID; | |
| + garray_T *gap2; | |
| +{ | |
| + int total_strlen = 0; | |
| + int i; | |
| + int len; | |
| + char_u **p; | |
| + | |
| + int first = TRUE; | |
| + char_u *tofree; | |
| + char_u numbuf[NUMBUFLEN]; | |
| + listitem_T *item; | |
| + char_u *s; | |
| + | |
| + /* Stringify each items in the list. */ | |
| + for (item = l->lv_first; item != NULL && !got_int; item = item->li_next) | |
| + { | |
| + ga_grow(gap2, 1); | |
| + p = ((char_u**)gap2->ga_data) + gap2->ga_len; | |
| + | |
| + if (echo_style) | |
| + s = echo_string(&item->li_tv, &tofree, numbuf, copyID); | |
| + else | |
| + s = tv2string(&item->li_tv, &tofree, numbuf, copyID); | |
| + if (s == NULL) | |
| + return FAIL; | |
| + | |
| + len = (int)STRLEN(s); | |
| + *p = vim_strnsave(s, len); | |
| + ++gap2->ga_len; | |
| + vim_free(tofree); | |
| + total_strlen += len; | |
| + line_breakcheck(); | |
| + } | |
| + | |
| + /* Allocate result buffer with its total size. */ | |
| + total_strlen += (int)STRLEN(sep) * (gap2->ga_len - 1); | |
| + ga_grow(gap, total_strlen + 1); | |
| + | |
| + p = (char_u**)gap2->ga_data; | |
| + for (i = 0; i < gap2->ga_len && !got_int; ++i, ++p) | |
| + { | |
| + if (first) | |
| + first = FALSE; | |
| + else | |
| + ga_concat(gap, sep); | |
| + if (*p != NULL) | |
| + ga_concat(gap, *p); | |
| + line_breakcheck(); | |
| + } | |
| + | |
| + return OK; | |
| +} | |
| + | |
| /* | |
| * Join list "l" into a string in "*gap", using separator "sep". | |
| * When "echo_style" is TRUE use String as echoed, otherwise as inside a List. | |
| @@ -6585,31 +6645,17 @@ | |
| int echo_style; | |
| int copyID; | |
| { | |
| - int first = TRUE; | |
| - char_u *tofree; | |
| - char_u numbuf[NUMBUFLEN]; | |
| - listitem_T *item; | |
| - char_u *s; | |
| - | |
| - for (item = l->lv_first; item != NULL && !got_int; item = item->li_next) | |
| - { | |
| - if (first) | |
| - first = FALSE; | |
| - else | |
| - ga_concat(gap, sep); | |
| - | |
| - if (echo_style) | |
| - s = echo_string(&item->li_tv, &tofree, numbuf, copyID); | |
| - else | |
| - s = tv2string(&item->li_tv, &tofree, numbuf, copyID); | |
| - if (s != NULL) | |
| - ga_concat(gap, s); | |
| - vim_free(tofree); | |
| - if (s == NULL) | |
| - return FAIL; | |
| - line_breakcheck(); | |
| - } | |
| - return OK; | |
| + garray_T str_array; | |
| + int retval; | |
| + | |
| + ga_init2(&str_array, (int)sizeof(char_u*), l->lv_len); | |
| + retval = list_join2(gap, l, sep, echo_style, copyID, &str_array); | |
| + | |
| + /* Dispose each items in str_array. */ | |
| + if (str_array.ga_data != NULL) | |
| + ga_clear_strings(&str_array); | |
| + | |
| + return retval; | |
| } | |
| /* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment