mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-25 21:46:14 +01:00
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:
parent
72a87d8629
commit
37cddec0ee
@ -42,11 +42,14 @@ static const GOptionEntry entries[] = {
|
|||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* 256k minus malloc overhead */
|
||||||
|
#define STREAM_BUFFER_SIZE (1024*256 - 2*sizeof(gpointer))
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
cat (GFile *file)
|
cat (GFile *file)
|
||||||
{
|
{
|
||||||
GInputStream *in;
|
GInputStream *in;
|
||||||
char buffer[1024 * 8 + 1];
|
char *buffer;
|
||||||
char *p;
|
char *p;
|
||||||
gssize res;
|
gssize res;
|
||||||
gboolean close_res;
|
gboolean close_res;
|
||||||
@ -62,10 +65,11 @@ cat (GFile *file)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buffer = g_malloc (STREAM_BUFFER_SIZE);
|
||||||
success = TRUE;
|
success = TRUE;
|
||||||
while (1)
|
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)
|
if (res > 0)
|
||||||
{
|
{
|
||||||
gssize written;
|
gssize written;
|
||||||
@ -109,6 +113,8 @@ cat (GFile *file)
|
|||||||
success = FALSE;
|
success = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_free (buffer);
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,12 +58,15 @@ static const GOptionEntry entries[] =
|
|||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* 256k minus malloc overhead */
|
||||||
|
#define STREAM_BUFFER_SIZE (1024*256 - 2*sizeof(gpointer))
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
save (GFile *file)
|
save (GFile *file)
|
||||||
{
|
{
|
||||||
GOutputStream *out;
|
GOutputStream *out;
|
||||||
GFileCreateFlags flags;
|
GFileCreateFlags flags;
|
||||||
char buffer[1025];
|
char *buffer;
|
||||||
char *p;
|
char *p;
|
||||||
gssize res;
|
gssize res;
|
||||||
gboolean close_res;
|
gboolean close_res;
|
||||||
@ -88,11 +91,12 @@ save (GFile *file)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buffer = g_malloc (STREAM_BUFFER_SIZE);
|
||||||
save_res = TRUE;
|
save_res = TRUE;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
res = read (STDIN_FILENO, buffer, 1024);
|
res = read (STDIN_FILENO, buffer, STREAM_BUFFER_SIZE);
|
||||||
if (res > 0)
|
if (res > 0)
|
||||||
{
|
{
|
||||||
gssize written;
|
gssize written;
|
||||||
@ -147,6 +151,7 @@ save (GFile *file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref (out);
|
g_object_unref (out);
|
||||||
|
g_free (buffer);
|
||||||
|
|
||||||
return save_res;
|
return save_res;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user