gio-tool: Unify buffer sizes

Recently, buffer size for copying has been increased in order to improve
performance:
https://bugzilla.gnome.org/show_bug.cgi?id=773823

Let's do the same for gio-tool-save and gio-tool-cat.

https://bugzilla.gnome.org/show_bug.cgi?id=786460
This commit is contained in:
Ondrej Holy 2017-08-11 13:21:28 +02:00
parent 72a87d8629
commit 37cddec0ee
2 changed files with 15 additions and 4 deletions

View File

@ -42,11 +42,14 @@ static const GOptionEntry entries[] = {
{ NULL }
};
/* 256k minus malloc overhead */
#define STREAM_BUFFER_SIZE (1024*256 - 2*sizeof(gpointer))
static gboolean
cat (GFile *file)
{
GInputStream *in;
char buffer[1024 * 8 + 1];
char *buffer;
char *p;
gssize res;
gboolean close_res;
@ -62,10 +65,11 @@ cat (GFile *file)
return FALSE;
}
buffer = g_malloc (STREAM_BUFFER_SIZE);
success = TRUE;
while (1)
{
res = g_input_stream_read (in, buffer, sizeof (buffer) - 1, NULL, &error);
res = g_input_stream_read (in, buffer, STREAM_BUFFER_SIZE, NULL, &error);
if (res > 0)
{
gssize written;
@ -109,6 +113,8 @@ cat (GFile *file)
success = FALSE;
}
g_free (buffer);
return success;
}

View File

@ -58,12 +58,15 @@ static const GOptionEntry entries[] =
{ NULL }
};
/* 256k minus malloc overhead */
#define STREAM_BUFFER_SIZE (1024*256 - 2*sizeof(gpointer))
static gboolean
save (GFile *file)
{
GOutputStream *out;
GFileCreateFlags flags;
char buffer[1025];
char *buffer;
char *p;
gssize res;
gboolean close_res;
@ -88,11 +91,12 @@ save (GFile *file)
return FALSE;
}
buffer = g_malloc (STREAM_BUFFER_SIZE);
save_res = TRUE;
while (1)
{
res = read (STDIN_FILENO, buffer, 1024);
res = read (STDIN_FILENO, buffer, STREAM_BUFFER_SIZE);
if (res > 0)
{
gssize written;
@ -147,6 +151,7 @@ save (GFile *file)
}
g_object_unref (out);
g_free (buffer);
return save_res;
}