mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-27 07:58:49 +01:00
add stream_getPtr() and use to remove a couple of allocs, including
one per message sent.
This commit is contained in:
parent
b579bb0bca
commit
63893b8a0d
4 changed files with 20 additions and 16 deletions
|
@ -2020,7 +2020,6 @@ send_via_relay( CommsCtxt* comms, XWRELAY_Cmd cmd, XWHostID destID,
|
||||||
XP_U16 len = 0;
|
XP_U16 len = 0;
|
||||||
CommsAddrRec addr;
|
CommsAddrRec addr;
|
||||||
XWStreamCtxt* tmpStream;
|
XWStreamCtxt* tmpStream;
|
||||||
XP_U8* buf;
|
|
||||||
|
|
||||||
comms_getAddr( comms, &addr );
|
comms_getAddr( comms, &addr );
|
||||||
tmpStream = mem_stream_make( MPPARM(comms->mpool)
|
tmpStream = mem_stream_make( MPPARM(comms->mpool)
|
||||||
|
@ -2101,22 +2100,17 @@ send_via_relay( CommsCtxt* comms, XWRELAY_Cmd cmd, XWHostID destID,
|
||||||
}
|
}
|
||||||
|
|
||||||
len = stream_getSize( tmpStream );
|
len = stream_getSize( tmpStream );
|
||||||
buf = XP_MALLOC( comms->mpool, len );
|
if ( 0 < len ) {
|
||||||
if ( buf != NULL ) {
|
|
||||||
stream_getBytes( tmpStream, buf, len );
|
|
||||||
}
|
|
||||||
stream_destroy( tmpStream );
|
|
||||||
if ( buf != NULL ) {
|
|
||||||
XP_U16 result;
|
XP_U16 result;
|
||||||
XP_LOGF( "%s: passing %d bytes to sendproc", __func__, len );
|
XP_LOGF( "%s: passing %d bytes to sendproc", __func__, len );
|
||||||
result = (*comms->procs.send)( buf, len, &addr,
|
result = (*comms->procs.send)( stream_getPtr(tmpStream), len,
|
||||||
comms->procs.closure );
|
&addr, comms->procs.closure );
|
||||||
success = result == len;
|
success = result == len;
|
||||||
if ( success ) {
|
if ( success ) {
|
||||||
setHeartbeatTimer( comms );
|
setHeartbeatTimer( comms );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
XP_FREE( comms->mpool, buf );
|
stream_destroy( tmpStream );
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
} /* send_via_relay */
|
} /* send_via_relay */
|
||||||
|
|
|
@ -301,7 +301,7 @@ mem_stream_copyFromStream( XWStreamCtxt* p_sctx, XWStreamCtxt* src,
|
||||||
if ( nBytes < len ) {
|
if ( nBytes < len ) {
|
||||||
len = nBytes;
|
len = nBytes;
|
||||||
}
|
}
|
||||||
stream_getBytes( src, buf, len );
|
stream_getBytes( src, buf, len );// fix to use stream_getPtr()?
|
||||||
stream_putBytes( p_sctx, buf, len );
|
stream_putBytes( p_sctx, buf, len );
|
||||||
nBytes -= len;
|
nBytes -= len;
|
||||||
}
|
}
|
||||||
|
@ -338,6 +338,13 @@ mem_stream_getSize( const XWStreamCtxt* p_sctx )
|
||||||
return size;
|
return size;
|
||||||
} /* mem_stream_getSize */
|
} /* mem_stream_getSize */
|
||||||
|
|
||||||
|
static const XP_U8*
|
||||||
|
mem_stream_getPtr( const XWStreamCtxt* p_sctx )
|
||||||
|
{
|
||||||
|
MemStreamCtxt* stream = (MemStreamCtxt*)p_sctx;
|
||||||
|
return stream->buf;
|
||||||
|
} /* mem_stream_getPtr */
|
||||||
|
|
||||||
static XP_PlayerAddr
|
static XP_PlayerAddr
|
||||||
mem_stream_getAddress( XWStreamCtxt* p_sctx )
|
mem_stream_getAddress( XWStreamCtxt* p_sctx )
|
||||||
{
|
{
|
||||||
|
@ -451,6 +458,7 @@ make_vtable( MemStreamCtxt* stream )
|
||||||
SET_VTABLE_ENTRY( vtable, stream_close, mem );
|
SET_VTABLE_ENTRY( vtable, stream_close, mem );
|
||||||
|
|
||||||
SET_VTABLE_ENTRY( vtable, stream_getSize, mem );
|
SET_VTABLE_ENTRY( vtable, stream_getSize, mem );
|
||||||
|
SET_VTABLE_ENTRY( vtable, stream_getPtr, mem );
|
||||||
SET_VTABLE_ENTRY( vtable, stream_getAddress, mem );
|
SET_VTABLE_ENTRY( vtable, stream_getAddress, mem );
|
||||||
SET_VTABLE_ENTRY( vtable, stream_setAddress, mem );
|
SET_VTABLE_ENTRY( vtable, stream_setAddress, mem );
|
||||||
|
|
||||||
|
|
|
@ -841,14 +841,11 @@ showPrevScore( ServerCtxt* server )
|
||||||
if ( !!server->nv.prevMoveStream ) {
|
if ( !!server->nv.prevMoveStream ) {
|
||||||
XWStreamCtxt* prevStream = server->nv.prevMoveStream;
|
XWStreamCtxt* prevStream = server->nv.prevMoveStream;
|
||||||
XP_U16 len = stream_getSize( prevStream );
|
XP_U16 len = stream_getSize( prevStream );
|
||||||
XP_UCHAR* buf = XP_MALLOC( server->mpool, len );
|
|
||||||
|
|
||||||
stream_getBytes( prevStream, buf, len );
|
|
||||||
stream_destroy( prevStream );
|
|
||||||
server->nv.prevMoveStream = NULL;
|
server->nv.prevMoveStream = NULL;
|
||||||
|
|
||||||
stream_putBytes( stream, buf, len );
|
stream_putBytes( stream, stream_getPtr( prevStream ), len );
|
||||||
XP_FREE( server->mpool, buf );
|
stream_destroy( prevStream );
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)util_userQuery( util, QUERY_ROBOT_MOVE, stream );
|
(void)util_userQuery( util, QUERY_ROBOT_MOVE, stream );
|
||||||
|
|
|
@ -69,6 +69,8 @@ typedef struct StreamCtxVTable {
|
||||||
void (*m_stream_close)( XWStreamCtxt* dctx );
|
void (*m_stream_close)( XWStreamCtxt* dctx );
|
||||||
|
|
||||||
XP_U16 (*m_stream_getSize)( const XWStreamCtxt* dctx );
|
XP_U16 (*m_stream_getSize)( const XWStreamCtxt* dctx );
|
||||||
|
|
||||||
|
const XP_U8* (*m_stream_getPtr)( const XWStreamCtxt* dctx );
|
||||||
|
|
||||||
/* void (*m_stream_makeReturnAddr)( XWStreamCtxt* dctx, XP_PlayerAddr* addr, */
|
/* void (*m_stream_makeReturnAddr)( XWStreamCtxt* dctx, XP_PlayerAddr* addr, */
|
||||||
/* XP_U16* addrLen ); */
|
/* XP_U16* addrLen ); */
|
||||||
|
@ -143,6 +145,9 @@ struct XWStreamCtxt {
|
||||||
#define stream_getSize(sc) \
|
#define stream_getSize(sc) \
|
||||||
(sc)->vtable->m_stream_getSize((sc))
|
(sc)->vtable->m_stream_getSize((sc))
|
||||||
|
|
||||||
|
#define stream_getPtr(sc) \
|
||||||
|
(sc)->vtable->m_stream_getPtr((sc))
|
||||||
|
|
||||||
#define stream_makeReturnAddr(sc,addr,len) \
|
#define stream_makeReturnAddr(sc,addr,len) \
|
||||||
(sc)->vtable->m_stream_makeReturnAddr((sc),(addr),(len))
|
(sc)->vtable->m_stream_makeReturnAddr((sc),(addr),(len))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue