Use g_strndup() instead of g_strdup()

...to ret rid of extra calculation of string length.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2012-08-31 13:07:20 +04:00 committed by Slava Zanko
parent 5e1ae44eca
commit 8b382756bf
4 changed files with 11 additions and 9 deletions

View File

@ -210,7 +210,7 @@ history_load (struct mc_config_t * cfg, const char *name)
hist = list_append_unique (hist, this_entry); hist = list_append_unique (hist, this_entry);
else else
{ {
hist = list_append_unique (hist, g_strdup (buffer->str)); hist = list_append_unique (hist, g_strndup (buffer->str, buffer->len));
g_free (this_entry); g_free (this_entry);
} }
} }

View File

@ -1280,7 +1280,7 @@ edit_collect_completions (WEdit * edit, off_t word_start, gsize word_len,
g_string_free (recoded, TRUE); g_string_free (recoded, TRUE);
} }
#endif #endif
compl[*num].text = g_strdup (temp->str); compl[*num].text = g_strndup (temp->str, temp->len);
compl[*num].len = temp->len; compl[*num].len = temp->len;
(*num)++; (*num)++;
start += len; start += len;

View File

@ -1426,7 +1426,8 @@ hot_load_group (struct hotlist *grp)
case TKN_GROUP: case TKN_GROUP:
CHECK_TOKEN (TKN_STRING); CHECK_TOKEN (TKN_STRING);
new_grp = new_grp =
add2hotlist (g_strdup (tkn_buf->str), 0, HL_TYPE_GROUP, LISTBOX_APPEND_AT_END); add2hotlist (g_strndup (tkn_buf->str, tkn_buf->len), 0, HL_TYPE_GROUP,
LISTBOX_APPEND_AT_END);
SKIP_TO_EOL; SKIP_TO_EOL;
hot_load_group (new_grp); hot_load_group (new_grp);
current_group = grp; current_group = grp;
@ -1434,7 +1435,7 @@ hot_load_group (struct hotlist *grp)
case TKN_ENTRY: case TKN_ENTRY:
{ {
CHECK_TOKEN (TKN_STRING); CHECK_TOKEN (TKN_STRING);
label = g_strdup (tkn_buf->str); label = g_strndup (tkn_buf->str, tkn_buf->len);
CHECK_TOKEN (TKN_URL); CHECK_TOKEN (TKN_URL);
CHECK_TOKEN (TKN_STRING); CHECK_TOKEN (TKN_STRING);
url = tilde_expand (tkn_buf->str); url = tilde_expand (tkn_buf->str);
@ -1443,7 +1444,7 @@ hot_load_group (struct hotlist *grp)
} }
break; break;
case TKN_COMMENT: case TKN_COMMENT:
label = g_strdup (tkn_buf->str); label = g_strndup (tkn_buf->str, tkn_buf->len);
add2hotlist (label, 0, HL_TYPE_COMMENT, LISTBOX_APPEND_AT_END); add2hotlist (label, 0, HL_TYPE_COMMENT, LISTBOX_APPEND_AT_END);
break; break;
case TKN_EOF: case TKN_EOF:
@ -1480,7 +1481,8 @@ hot_load_file (struct hotlist *grp)
case TKN_GROUP: case TKN_GROUP:
CHECK_TOKEN (TKN_STRING); CHECK_TOKEN (TKN_STRING);
new_grp = new_grp =
add2hotlist (g_strdup (tkn_buf->str), 0, HL_TYPE_GROUP, LISTBOX_APPEND_AT_END); add2hotlist (g_strndup (tkn_buf->str, tkn_buf->len), 0, HL_TYPE_GROUP,
LISTBOX_APPEND_AT_END);
SKIP_TO_EOL; SKIP_TO_EOL;
hot_load_group (new_grp); hot_load_group (new_grp);
current_group = grp; current_group = grp;
@ -1488,7 +1490,7 @@ hot_load_file (struct hotlist *grp)
case TKN_ENTRY: case TKN_ENTRY:
{ {
CHECK_TOKEN (TKN_STRING); CHECK_TOKEN (TKN_STRING);
label = g_strdup (tkn_buf->str); label = g_strndup (tkn_buf->str, tkn_buf->len);
CHECK_TOKEN (TKN_URL); CHECK_TOKEN (TKN_URL);
CHECK_TOKEN (TKN_STRING); CHECK_TOKEN (TKN_STRING);
url = tilde_expand (tkn_buf->str); url = tilde_expand (tkn_buf->str);
@ -1497,7 +1499,7 @@ hot_load_file (struct hotlist *grp)
} }
break; break;
case TKN_COMMENT: case TKN_COMMENT:
label = g_strdup (tkn_buf->str); label = g_strndup (tkn_buf->str, tkn_buf->len);
add2hotlist (label, 0, HL_TYPE_COMMENT, LISTBOX_APPEND_AT_END); add2hotlist (label, 0, HL_TYPE_COMMENT, LISTBOX_APPEND_AT_END);
break; break;
case TKN_EOL: case TKN_EOL:

View File

@ -4570,7 +4570,7 @@ remove_encoding_from_path (const vfs_path_t * vpath)
str_vfs_convert_from (converter, path_element->path, tmp_conv); str_vfs_convert_from (converter, path_element->path, tmp_conv);
g_free (path_element->path); g_free (path_element->path);
path_element->path = g_strdup (tmp_conv->str); path_element->path = g_strndup (tmp_conv->str, tmp_conv->len);
g_string_set_size (tmp_conv, 0); g_string_set_size (tmp_conv, 0);