mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-23 19:52:12 +03:00
(get_random_hint): minor optimisation and type accuracy.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
28ce7e566e
commit
1e302a3c63
@ -1334,11 +1334,10 @@ user_file_menu_cmd (void)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
char *
|
char *
|
||||||
get_random_hint (int force)
|
get_random_hint (gboolean force)
|
||||||
{
|
{
|
||||||
char *data, *result = NULL, *eop;
|
char *data, *result = NULL, *eop;
|
||||||
size_t len;
|
size_t len, start;
|
||||||
int start;
|
|
||||||
static int last_sec;
|
static int last_sec;
|
||||||
static struct timeval tv;
|
static struct timeval tv;
|
||||||
GIConv conv;
|
GIConv conv;
|
||||||
@ -1355,7 +1354,7 @@ get_random_hint (int force)
|
|||||||
|
|
||||||
/* get a random entry */
|
/* get a random entry */
|
||||||
srand (tv.tv_sec);
|
srand (tv.tv_sec);
|
||||||
start = rand () % (len - 1);
|
start = ((size_t) rand ()) % (len - 1);
|
||||||
|
|
||||||
/* Search the start of paragraph */
|
/* Search the start of paragraph */
|
||||||
for (; start != 0; start--)
|
for (; start != 0; start--)
|
||||||
@ -1384,7 +1383,7 @@ get_random_hint (int force)
|
|||||||
{
|
{
|
||||||
GString *buffer;
|
GString *buffer;
|
||||||
|
|
||||||
buffer = g_string_new ("");
|
buffer = g_string_sized_new (len - start);
|
||||||
if (str_convert (conv, &data[start], buffer) != ESTR_FAILURE)
|
if (str_convert (conv, &data[start], buffer) != ESTR_FAILURE)
|
||||||
result = g_string_free (buffer, FALSE);
|
result = g_string_free (buffer, FALSE);
|
||||||
else
|
else
|
||||||
@ -1392,7 +1391,7 @@ get_random_hint (int force)
|
|||||||
str_close_conv (conv);
|
str_close_conv (conv);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
result = g_strdup (&data[start]);
|
result = g_strndup (data + start, len - start);
|
||||||
|
|
||||||
g_free (data);
|
g_free (data);
|
||||||
return result;
|
return result;
|
||||||
|
@ -83,7 +83,7 @@ void swap_cmd (void);
|
|||||||
void view_other_cmd (void);
|
void view_other_cmd (void);
|
||||||
void quick_cd_cmd (void);
|
void quick_cd_cmd (void);
|
||||||
void save_setup_cmd (void);
|
void save_setup_cmd (void);
|
||||||
char *get_random_hint (int force);
|
char *get_random_hint (gboolean force);
|
||||||
void user_file_menu_cmd (void);
|
void user_file_menu_cmd (void);
|
||||||
void info_cmd (void);
|
void info_cmd (void);
|
||||||
void listing_cmd (void);
|
void listing_cmd (void);
|
||||||
|
Loading…
Reference in New Issue
Block a user