1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-02 13:00:26 +02:00

Remove unnecessary scm_i_string_start_writing calls

* libguile/strings.c (scm_string, scm_c_make_string):
* libguile/srfi-13.c (scm_reverse_list_to_string, scm_string_map)
  (scm_string_unfold, scm_string_unfold_right, scm_xsubstring)
  (scm_string_filter, scm_string_delete): Remove
  scm_i_string_start_writing / scm_i_string_stop_writing calls around
  fresh strings that aren't visible to other threads.
This commit is contained in:
Andy Wingo 2017-02-16 10:43:23 +01:00
parent cd3ff33a31
commit c38b9625c8
3 changed files with 16 additions and 25 deletions

View file

@ -1556,7 +1556,8 @@ scm_read_extended_symbol (scm_t_wchar chr, SCM port)
size_t len = 0; size_t len = 0;
SCM buf = scm_i_make_string (1024, NULL, 0); SCM buf = scm_i_make_string (1024, NULL, 0);
buf = scm_i_string_start_writing (buf); /* No need to scm_i_string_start_writing (), as the string isn't
visible to any other thread. */
while ((chr = scm_getc (port)) != EOF) while ((chr = scm_getc (port)) != EOF)
{ {
@ -1620,16 +1621,13 @@ scm_read_extended_symbol (scm_t_wchar chr, SCM port)
{ {
SCM addy; SCM addy;
scm_i_string_stop_writing ();
addy = scm_i_make_string (1024, NULL, 0); addy = scm_i_make_string (1024, NULL, 0);
buf = scm_string_append (scm_list_2 (buf, addy)); buf = scm_string_append (scm_list_2 (buf, addy));
len = 0; len = 0;
buf = scm_i_string_start_writing (buf);
} }
} }
done: done:
scm_i_string_stop_writing ();
if (chr == EOF) if (chr == EOF)
scm_i_input_error ("scm_read_extended_symbol", port, scm_i_input_error ("scm_read_extended_symbol", port,
"end of file while reading symbol", SCM_EOL); "end of file while reading symbol", SCM_EOL);

View file

@ -351,7 +351,8 @@ SCM_DEFINE (scm_reverse_list_to_string, "reverse-list->string", 1, 0, 0,
} }
rest = chrs; rest = chrs;
j = i; j = i;
result = scm_i_string_start_writing (result); /* No need to scm_i_string_start_writing (), as the string isn't
visible to any other thread. */
while (j > 0 && scm_is_pair (rest)) while (j > 0 && scm_is_pair (rest))
{ {
SCM elt = SCM_CAR (rest); SCM elt = SCM_CAR (rest);
@ -359,7 +360,6 @@ SCM_DEFINE (scm_reverse_list_to_string, "reverse-list->string", 1, 0, 0,
rest = SCM_CDR (rest); rest = SCM_CDR (rest);
j--; j--;
} }
scm_i_string_stop_writing ();
} }
return result; return result;
@ -2515,9 +2515,9 @@ SCM_DEFINE (scm_string_map, "string-map", 2, 2, 0,
if (!SCM_CHARP (ch)) if (!SCM_CHARP (ch))
SCM_MISC_ERROR ("procedure ~S returned non-char", scm_list_1 (proc)); SCM_MISC_ERROR ("procedure ~S returned non-char", scm_list_1 (proc));
cstart++; cstart++;
result = scm_i_string_start_writing (result); /* No need to scm_i_string_start_writing (), as the string isn't
visible to any other thread. */
scm_i_string_set_x (result, p, SCM_CHAR (ch)); scm_i_string_set_x (result, p, SCM_CHAR (ch));
scm_i_string_stop_writing ();
p++; p++;
} }
@ -2658,9 +2658,9 @@ SCM_DEFINE (scm_string_unfold, "string-unfold", 4, 2, 0,
if (!SCM_CHARP (ch)) if (!SCM_CHARP (ch))
SCM_MISC_ERROR ("procedure ~S returned non-char", scm_list_1 (f)); SCM_MISC_ERROR ("procedure ~S returned non-char", scm_list_1 (f));
str = scm_i_make_string (1, NULL, 0); str = scm_i_make_string (1, NULL, 0);
str = scm_i_string_start_writing (str); /* No need to scm_i_string_start_writing (), as the string isn't
visible to any other thread. */
scm_i_string_set_x (str, i, SCM_CHAR (ch)); scm_i_string_set_x (str, i, SCM_CHAR (ch));
scm_i_string_stop_writing ();
i++; i++;
ans = scm_string_append (scm_list_2 (ans, str)); ans = scm_string_append (scm_list_2 (ans, str));
@ -2724,9 +2724,9 @@ SCM_DEFINE (scm_string_unfold_right, "string-unfold-right", 4, 2, 0,
if (!SCM_CHARP (ch)) if (!SCM_CHARP (ch))
SCM_MISC_ERROR ("procedure ~S returned non-char", scm_list_1 (f)); SCM_MISC_ERROR ("procedure ~S returned non-char", scm_list_1 (f));
str = scm_i_make_string (1, NULL, 0); str = scm_i_make_string (1, NULL, 0);
str = scm_i_string_start_writing (str); /* No need to scm_i_string_start_writing (), as the string isn't
visible to any other thread. */
scm_i_string_set_x (str, i, SCM_CHAR (ch)); scm_i_string_set_x (str, i, SCM_CHAR (ch));
scm_i_string_stop_writing ();
i++; i++;
ans = scm_string_append (scm_list_2 (str, ans)); ans = scm_string_append (scm_list_2 (str, ans));
@ -2839,7 +2839,6 @@ SCM_DEFINE (scm_xsubstring, "xsubstring", 2, 3, 0,
SCM_MISC_ERROR ("start and end indices must not be equal", SCM_EOL); SCM_MISC_ERROR ("start and end indices must not be equal", SCM_EOL);
result = scm_i_make_string (cto - cfrom, NULL, 0); result = scm_i_make_string (cto - cfrom, NULL, 0);
result = scm_i_string_start_writing (result);
p = 0; p = 0;
while (cfrom < cto) while (cfrom < cto)
@ -2853,7 +2852,6 @@ SCM_DEFINE (scm_xsubstring, "xsubstring", 2, 3, 0,
cfrom++; cfrom++;
p++; p++;
} }
scm_i_string_stop_writing ();
scm_remember_upto_here_1 (s); scm_remember_upto_here_1 (s);
return result; return result;
@ -3191,8 +3189,9 @@ SCM_DEFINE (scm_string_filter, "string-filter", 2, 2, 0,
{ {
size_t dst = 0; size_t dst = 0;
result = scm_i_make_string (count, NULL, 0); result = scm_i_make_string (count, NULL, 0);
result = scm_i_string_start_writing (result);
/* No need to scm_i_string_start_writing (), as the string isn't
visible to any other thread. */
/* decrement "count" in this loop as well as using idx, so that if /* decrement "count" in this loop as well as using idx, so that if
another thread is simultaneously changing "s" there's no chance another thread is simultaneously changing "s" there's no chance
it'll make us copy more than count characters */ it'll make us copy more than count characters */
@ -3205,7 +3204,6 @@ SCM_DEFINE (scm_string_filter, "string-filter", 2, 2, 0,
count--; count--;
} }
} }
scm_i_string_stop_writing ();
} }
} }
else else
@ -3301,7 +3299,8 @@ SCM_DEFINE (scm_string_delete, "string-delete", 2, 2, 0,
int i = 0; int i = 0;
/* new string for retained portion */ /* new string for retained portion */
result = scm_i_make_string (count, NULL, 0); result = scm_i_make_string (count, NULL, 0);
result = scm_i_string_start_writing (result); /* No need to scm_i_string_start_writing (), as the string isn't
visible to any other thread. */
/* decrement "count" in this loop as well as using idx, so that if /* decrement "count" in this loop as well as using idx, so that if
another thread is simultaneously changing "s" there's no chance another thread is simultaneously changing "s" there's no chance
it'll make us copy more than count characters */ it'll make us copy more than count characters */
@ -3315,7 +3314,6 @@ SCM_DEFINE (scm_string_delete, "string-delete", 2, 2, 0,
count--; count--;
} }
} }
scm_i_string_stop_writing ();
} }
} }
else if (SCM_CHARSETP (char_pred)) else if (SCM_CHARSETP (char_pred))
@ -3343,8 +3341,9 @@ SCM_DEFINE (scm_string_delete, "string-delete", 2, 2, 0,
size_t i = 0; size_t i = 0;
/* new string for retained portion */ /* new string for retained portion */
result = scm_i_make_string (count, NULL, 0); result = scm_i_make_string (count, NULL, 0);
result = scm_i_string_start_writing (result);
/* No need to scm_i_string_start_writing (), as the string isn't
visible to any other thread. */
/* decrement "count" in this loop as well as using idx, so that if /* decrement "count" in this loop as well as using idx, so that if
another thread is simultaneously changing "s" there's no chance another thread is simultaneously changing "s" there's no chance
it'll make us copy more than count characters */ it'll make us copy more than count characters */
@ -3357,7 +3356,6 @@ SCM_DEFINE (scm_string_delete, "string-delete", 2, 2, 0,
count--; count--;
} }
} }
scm_i_string_stop_writing ();
} }
} }
else else

View file

@ -1145,7 +1145,6 @@ SCM_DEFINE (scm_string, "string", 0, 0, 1,
char *buf; char *buf;
result = scm_i_make_string (len, NULL, 0); result = scm_i_make_string (len, NULL, 0);
result = scm_i_string_start_writing (result);
buf = scm_i_string_writable_chars (result); buf = scm_i_string_writable_chars (result);
while (len > 0 && scm_is_pair (rest)) while (len > 0 && scm_is_pair (rest))
{ {
@ -1162,7 +1161,6 @@ SCM_DEFINE (scm_string, "string", 0, 0, 1,
scm_t_wchar *buf; scm_t_wchar *buf;
result = scm_i_make_wide_string (len, NULL, 0); result = scm_i_make_wide_string (len, NULL, 0);
result = scm_i_string_start_writing (result);
buf = scm_i_string_writable_wide_chars (result); buf = scm_i_string_writable_wide_chars (result);
while (len > 0 && scm_is_pair (rest)) while (len > 0 && scm_is_pair (rest))
{ {
@ -1174,7 +1172,6 @@ SCM_DEFINE (scm_string, "string", 0, 0, 1,
scm_remember_upto_here_1 (elt); scm_remember_upto_here_1 (elt);
} }
} }
scm_i_string_stop_writing ();
if (len > 0) if (len > 0)
scm_misc_error (NULL, "list changed while constructing string", SCM_EOL); scm_misc_error (NULL, "list changed while constructing string", SCM_EOL);
@ -1211,10 +1208,8 @@ scm_c_make_string (size_t len, SCM chr)
else else
{ {
SCM_VALIDATE_CHAR (0, chr); SCM_VALIDATE_CHAR (0, chr);
res = scm_i_string_start_writing (res);
for (p = 0; p < len; p++) for (p = 0; p < len; p++)
scm_i_string_set_x (res, p, SCM_CHAR (chr)); scm_i_string_set_x (res, p, SCM_CHAR (chr));
scm_i_string_stop_writing ();
} }
return res; return res;