[gnio] Avoid unnecessary use of alloca
- From: Alexander Larsson <alexl src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnio] Avoid unnecessary use of alloca
- Date: Tue, 28 Apr 2009 06:09:23 -0400 (EDT)
commit 4de1eeb0951ffb57347f6eabddb5fec3b6190fa6
Author: Alexander Larsson <alexl redhat com>
Date: Tue Apr 28 11:13:49 2009 +0200
Avoid unnecessary use of alloca
I don't see the point of using alloca for statically known sizes. The
only possible advantage is that space on the stack is not always
allocated, but thats something the compiler could optimize anyway, and
some extra space in the stack frame for a short-living edge function
like this is no cost anyway.
---
gio/gsocket.c | 20 +++++++++++---------
1 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/gio/gsocket.c b/gio/gsocket.c
index 01fa3e6..1be66f4 100644
--- a/gio/gsocket.c
+++ b/gio/gsocket.c
@@ -998,6 +998,8 @@ g_socket_send_message (GSocket *socket,
{
struct msghdr msg;
gssize result;
+ char zero;
+ struct iovec one_iovec;
if (!check_socket (socket, error))
return -1;
@@ -1020,13 +1022,10 @@ g_socket_send_message (GSocket *socket,
if (num_vectors == 0)
{
- char *zero;
+ zero = '\0';
- zero = g_newa (char, 1);
- *zero = '\0';
-
- msg.msg_iov = g_newa (struct iovec, 1);
- msg.msg_iov->iov_base = zero;
+ msg.msg_iov = &one_iovec;
+ msg.msg_iov->iov_base = &zero;
msg.msg_iov->iov_len = 1;
msg.msg_iovlen = 1;
}
@@ -1171,6 +1170,9 @@ g_socket_receive_message (GSocket *socket,
{
struct msghdr msg;
gssize result;
+ struct sockaddr_storage one_sockaddr;
+ struct iovec one_iovec;
+ char one_byte;
if (!check_socket (socket, error))
return -1;
@@ -1179,7 +1181,7 @@ g_socket_receive_message (GSocket *socket,
{
if (address)
{
- msg.msg_name = g_newa (struct sockaddr_storage, 1);
+ msg.msg_name = &one_sockaddr;
msg.msg_namelen = sizeof (struct sockaddr_storage);
}
else
@@ -1193,8 +1195,8 @@ g_socket_receive_message (GSocket *socket,
{
if (num_vectors == 0)
{
- msg.msg_iov = g_newa (struct iovec, 1);
- msg.msg_iov->iov_base = g_newa (char, 1);
+ msg.msg_iov = &one_iovec;
+ msg.msg_iov->iov_base = &one_byte;
msg.msg_iov->iov_len = 1;
msg.msg_iovlen = 1;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]