
marvin at rectangular
Sep 17, 2008, 6:18 PM
Post #1 of 1
(2428 views)
Permalink
|
|
r3877 - trunk/c_src/KinoSearch/Store
|
|
Author: creamyg Date: 2008-09-17 18:18:15 -0700 (Wed, 17 Sep 2008) New Revision: 3877 Modified: trunk/c_src/KinoSearch/Store/InStream.c trunk/c_src/KinoSearch/Store/OutStream.c Log: Inline some functions in InStream and OutStream. Modified: trunk/c_src/KinoSearch/Store/InStream.c =================================================================== --- trunk/c_src/KinoSearch/Store/InStream.c 2008-09-18 00:16:26 UTC (rev 3876) +++ trunk/c_src/KinoSearch/Store/InStream.c 2008-09-18 01:18:15 UTC (rev 3877) @@ -9,12 +9,15 @@ do_init(InStream *self, FileDes *file_des, CharBuf *filename, u64_t offset, u64_t len); -static void +static INLINE void refill(InStream *self); -static void +static INLINE void read_internal(InStream *self, char *dest, u32_t dest_offset, u32_t len); +static INLINE void +do_read_bytes (InStream *self, char* buf, size_t len); + InStream* InStream_new(FileDes *file_des) { @@ -71,7 +74,7 @@ FREE_OBJ(self); } -static void +static INLINE void refill(InStream *self) { const u64_t file_len = InStream_Length(self); @@ -101,7 +104,7 @@ read_internal(self, self->buf, 0, self->buf_len); } -static void +static INLINE void read_internal(InStream *self, char *dest, u32_t dest_offset, u32_t len) { FileDes *file_des = self->file_des; @@ -149,6 +152,12 @@ void InStream_read_bytes (InStream *self, char* buf, size_t len) { + do_read_bytes(self, buf, len); +} + +static INLINE void +do_read_bytes (InStream *self, char* buf, size_t len) +{ size_t available = self->buf_len - self->buf_pos; if (available >= len) { /* Request is entirely within buffer, so copy. */ @@ -190,7 +199,7 @@ InStream_read_byteso(InStream *self, char *buf, size_t start, size_t len) { buf += start; - InStream_Read_Bytes(self, buf, len); + do_read_bytes(self, buf, len); } static INLINE u8_t @@ -217,7 +226,7 @@ read_u32 (InStream *self) { u32_t retval; - InStream_Read_Bytes(self, (char*)&retval, 4); + do_read_bytes(self, (char*)&retval, 4); #ifdef LITTLE_END MATH_DECODE_U32(retval, &retval); #endif @@ -244,7 +253,7 @@ u32_t scratch; /* Get 8 bytes from the stream. */ - InStream_Read_Bytes(self, (char*)buf, 8); + do_read_bytes(self, (char*)buf, 8); MATH_DECODE_U32(aQuad, buf); aQuad <<= 32; @@ -270,7 +279,7 @@ InStream_read_float(InStream *self) { union { float f; u32_t u32; } retval; - InStream_Read_Bytes(self, (char*)&retval, sizeof(float)); + do_read_bytes(self, (char*)&retval, sizeof(float)); #ifdef LITTLE_END MATH_DECODE_U32(retval.u32, &retval); #endif @@ -282,7 +291,7 @@ { u32_t aU32 = 0; while (1) { - const u8_t aUByte = InStream_Read_U8(self); + const u8_t aUByte = read_u8(self); aU32 = (aU32 << 7) | (aUByte & 0x7f); if ((aUByte & 0x80) == 0) break; @@ -295,7 +304,7 @@ { u64_t aQuad = 0; while (1) { - const u8_t aUByte = InStream_Read_U8(self); + const u8_t aUByte = read_u8(self); aQuad = (aQuad << 7) | (aUByte & 0x7f); if ((aUByte & 0x80) == 0) break; @@ -308,7 +317,7 @@ { u8_t *dest = (u8_t*)buf; do { - *dest = InStream_Read_U8(self); + *dest = read_u8(self); } while ((*dest++ & 0x80) != 0); return dest - (u8_t*)buf; } Modified: trunk/c_src/KinoSearch/Store/OutStream.c =================================================================== --- trunk/c_src/KinoSearch/Store/OutStream.c 2008-09-18 00:16:26 UTC (rev 3876) +++ trunk/c_src/KinoSearch/Store/OutStream.c 2008-09-18 01:18:15 UTC (rev 3877) @@ -4,6 +4,15 @@ #include "KinoSearch/Store/FileDes.h" #include "KinoSearch/Store/InStream.h" +static INLINE void +do_flush(OutStream *self); + +static INLINE void +do_write_bytes(OutStream *self, const char *bytes, size_t len); + +static INLINE void +do_write_c32(OutStream *self, u32_t aU32); + OutStream* OutStream_new(FileDes *file_des) { @@ -29,7 +38,7 @@ OutStream_destroy(OutStream *self) { if (self->file_des != NULL) { - OutStream_Flush(self); + do_flush(self); REFCOUNT_DEC(self->file_des); } free(self->buf); @@ -47,7 +56,7 @@ ? (u32_t)bytes_left : IO_STREAM_BUF_SIZE; InStream_Read_Bytes(instream, buf, bytes_this_iter); - OutStream_write_bytes(self, buf, bytes_this_iter); + do_write_bytes(self, buf, bytes_this_iter); bytes_left -= bytes_this_iter; } } @@ -61,6 +70,12 @@ void OutStream_flush(OutStream *self) { + do_flush(self); +} + +static INLINE void +do_flush(OutStream *self) +{ if (self->file_des == NULL) CONFESS("Can't write to a closed OutStream"); if ( !FileDes_Write(self->file_des, self->buf, self->buf_pos) ) { @@ -73,23 +88,29 @@ u64_t OutStream_length(OutStream *self) { - OutStream_Flush(self); + do_flush(self); return FileDes_Length(self->file_des); } void OutStream_write_bytes(OutStream *self, const char *bytes, size_t len) { + do_write_bytes(self, bytes, len); +} + +static INLINE void +do_write_bytes(OutStream *self, const char *bytes, size_t len) +{ /* If this data is larger than the buffer size, flush and write. */ if (len >= IO_STREAM_BUF_SIZE) { - OutStream_Flush(self); + do_flush(self); if ( !FileDes_Write(self->file_des, bytes, len) ) CONFESS("Error: %o", FileDes_Get_Mess(self->file_des)); self->buf_start += len; } /* If there's not enough room in the buffer, flush then add. */ else if (self->buf_pos + len >= IO_STREAM_BUF_SIZE) { - OutStream_Flush(self); + do_flush(self); memcpy((self->buf + self->buf_pos), bytes, len * sizeof(char)); self->buf_pos += len; @@ -106,7 +127,7 @@ write_u8(OutStream *self, u8_t aU8) { if (self->buf_pos >= IO_STREAM_BUF_SIZE) - OutStream_Flush(self); + do_flush(self); self->buf[ self->buf_pos++ ] = (char)aU8; } @@ -126,11 +147,11 @@ write_u32(OutStream *self, u32_t aU32) { #ifdef BIG_END - OutStream_Write_Bytes(self, (char*)&aU32, 4); + do_write_bytes(self, (char*)&aU32, 4); #else u8_t buf[4]; MATH_ENCODE_U32(aU32, buf); - OutStream_Write_Bytes(self, (char*)buf, 4); + do_write_bytes(self, (char*)buf, 4); #endif } @@ -162,7 +183,7 @@ buf[7] = (aQuad ) & 0xFF; /* Print encoded Long to the output handle. */ - OutStream_Write_Bytes(self, (char*)buf, 8); + do_write_bytes(self, (char*)buf, 8); } void @@ -181,19 +202,25 @@ OutStream_write_float(OutStream *self, float aFloat) { #ifdef BIG_END - OutStream_Write_Bytes(self, (char*)&aFloat, sizeof(float)); + do_write_bytes(self, (char*)&aFloat, sizeof(float)); #else u8_t buf[sizeof(float)]; union { float f; u32_t u32; } duo; duo.f = aFloat; MATH_ENCODE_U32(duo.u32, buf); - OutStream_Write_Bytes(self, (char*)buf, 4); + do_write_bytes(self, (char*)buf, 4); #endif } void OutStream_write_c32(OutStream *self, u32_t aU32) { + do_write_c32(self, aU32); +} + +static INLINE void +do_write_c32(OutStream *self, u32_t aU32) +{ u8_t buf[C32_MAX_BYTES]; u8_t *ptr = buf + sizeof(buf) - 1; @@ -207,7 +234,7 @@ aU32 >>= 7; } - OutStream_write_bytes(self, (char*)ptr, (buf + sizeof(buf)) - ptr); + do_write_bytes(self, (char*)ptr, (buf + sizeof(buf)) - ptr); } void @@ -226,20 +253,20 @@ aQuad >>= 7; } - OutStream_write_bytes(self, (char*)ptr, (buf + sizeof(buf)) - ptr); + do_write_bytes(self, (char*)ptr, (buf + sizeof(buf)) - ptr); } void OutStream_write_string(OutStream *self, const char *string, size_t len) { - OutStream_write_c32(self, (u32_t)len); - OutStream_write_bytes(self, string, len); + do_write_c32(self, (u32_t)len); + do_write_bytes(self, string, len); } void OutStream_close(OutStream *self) { - OutStream_Flush(self); + do_flush(self); REFCOUNT_DEC(self->file_des); self->file_des = NULL; } _______________________________________________ kinosearch-commits mailing list kinosearch-commits [at] rectangular http://www.rectangular.com/mailman/listinfo/kinosearch-commits
|