Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix: pack uv structs more
Browse files Browse the repository at this point in the history
Try to avoid alignment holes on x86_64. Shaves off 4-8 bytes from most structs.
  • Loading branch information
bnoordhuis committed May 24, 2012
1 parent 752ac30 commit 793a52f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
15 changes: 10 additions & 5 deletions include/uv-private/uv-unix.h
Expand Up @@ -132,8 +132,8 @@ struct uv__io_s {
#define UV_UDP_SEND_PRIVATE_FIELDS \
ngx_queue_t queue; \
struct sockaddr_in6 addr; \
uv_buf_t* bufs; \
int bufcnt; \
uv_buf_t* bufs; \
ssize_t status; \
uv_udp_send_cb send_cb; \
uv_buf_t bufsml[UV_REQ_BUFSML_SIZE]; \
Expand All @@ -143,7 +143,6 @@ struct uv__io_s {

/* TODO: union or classes please! */
#define UV_HANDLE_PRIVATE_FIELDS \
int fd; \
int flags; \
uv_handle_t* next_pending; \

Expand All @@ -155,9 +154,10 @@ struct uv__io_s {
uv__io_t write_watcher; \
ngx_queue_t write_queue; \
ngx_queue_t write_completed_queue; \
int delayed_error; \
uv_connection_cb connection_cb; \
int delayed_error; \
int accepted_fd; \
int fd; \


/* UV_TCP */
Expand All @@ -166,6 +166,7 @@ struct uv__io_s {

/* UV_UDP */
#define UV_UDP_PRIVATE_FIELDS \
int fd; \
uv_alloc_cb alloc_cb; \
uv_udp_recv_cb recv_cb; \
uv__io_t read_watcher; \
Expand All @@ -181,6 +182,7 @@ struct uv__io_s {

/* UV_POLL */
#define UV_POLL_PRIVATE_FIELDS \
int fd; \
uv__io_t io_watcher;


Expand Down Expand Up @@ -246,7 +248,8 @@ struct uv__io_s {
struct uv_fs_event_s* rbe_parent; \
int rbe_color; \
} node; \
uv_fs_event_cb cb;
uv_fs_event_cb cb; \
int fd; \

#elif defined(__APPLE__) \
|| defined(__FreeBSD__) \
Expand All @@ -258,14 +261,16 @@ struct uv__io_s {
ev_io event_watcher; \
uv_fs_event_cb cb; \
int fflags; \
int fd;

#elif defined(__sun)

#ifdef PORT_SOURCE_FILE
# define UV_FS_EVENT_PRIVATE_FIELDS \
ev_io event_watcher; \
uv_fs_event_cb cb; \
file_obj_t fo;
file_obj_t fo; \
int fd;
#else /* !PORT_SOURCE_FILE */
# define UV_FS_EVENT_PRIVATE_FIELDS
#endif
Expand Down
29 changes: 15 additions & 14 deletions include/uv.h
Expand Up @@ -341,13 +341,13 @@ UV_EXTERN const char* uv_err_name(uv_err_t err);
#endif

#define UV_REQ_FIELDS \
/* read-only */ \
uv_req_type type; \
/* public */ \
void* data; \
UV_REQ_EXTRA_FIELDS \
/* private */ \
UV_REQ_PRIVATE_FIELDS
UV_REQ_PRIVATE_FIELDS \
/* read-only */ \
uv_req_type type; \

/* Abstract base class of all requests. */
struct uv_req_s {
Expand Down Expand Up @@ -384,16 +384,17 @@ struct uv_shutdown_s {
# define UV_HANDLE_EXTRA_FIELDS
#endif

#define UV_HANDLE_FIELDS \
/* read-only */ \
uv_loop_t* loop; \
uv_handle_type type; \
/* public */ \
uv_close_cb close_cb; \
void* data; \
UV_HANDLE_EXTRA_FIELDS \
/* private */ \
UV_HANDLE_PRIVATE_FIELDS
#define UV_HANDLE_FIELDS \
/* read-only */ \
uv_loop_t* loop; \
/* public */ \
uv_close_cb close_cb; \
void* data; \
/* read-only */ \
uv_handle_type type; \
/* private */ \
UV_HANDLE_PRIVATE_FIELDS \
UV_HANDLE_EXTRA_FIELDS \

/* The abstract base class of all handles. */
struct uv_handle_s {
Expand Down Expand Up @@ -1365,8 +1366,8 @@ typedef enum {
/* uv_fs_t is a subclass of uv_req_t */
struct uv_fs_s {
UV_REQ_FIELDS
uv_loop_t* loop;
uv_fs_type fs_type;
uv_loop_t* loop;
uv_fs_cb cb;
ssize_t result;
void* ptr;
Expand Down

0 comments on commit 793a52f

Please sign in to comment.