[MPlayer-cvslog] r30796 - in trunk/stream: stream.c stream.h
reimar
subversion at mplayerhq.hu
Sun Feb 28 14:54:55 CET 2010
Author: reimar
Date: Sun Feb 28 14:54:55 2010
New Revision: 30796
Log:
Move stream_read_line implementation from stream.h to stream.c,
it is not speed critical and the function call overhead is not
relevant for its overall speed anyway.
Modified:
trunk/stream/stream.c
trunk/stream/stream.h
Modified: trunk/stream/stream.c
==============================================================================
--- trunk/stream/stream.c Sun Feb 28 13:54:12 2010 (r30795)
+++ trunk/stream/stream.c Sun Feb 28 14:54:55 2010 (r30796)
@@ -487,3 +487,29 @@ int stream_check_interrupt(int time) {
if(!stream_check_interrupt_cb) return 0;
return stream_check_interrupt_cb(time);
}
+
+unsigned char* stream_read_line(stream_t *s,unsigned char* mem, int max) {
+ int len;
+ unsigned char* end,*ptr = mem;
+ if (max < 1) return NULL;
+ max--; // reserve one for 0-termination
+ do {
+ len = s->buf_len-s->buf_pos;
+ // try to fill the buffer
+ if(len <= 0 &&
+ (!cache_stream_fill_buffer(s) ||
+ (len = s->buf_len-s->buf_pos) <= 0)) break;
+ end = (unsigned char*) memchr((void*)(s->buffer+s->buf_pos),'\n',len);
+ if(end) len = end - (s->buffer+s->buf_pos) + 1;
+ if(len > 0 && max > 0) {
+ int l = len > max ? max : len;
+ memcpy(ptr,s->buffer+s->buf_pos,l);
+ max -= l;
+ ptr += l;
+ }
+ s->buf_pos += len;
+ } while(!end);
+ if(s->eof && ptr == mem) return NULL;
+ ptr[0] = 0;
+ return mem;
+}
Modified: trunk/stream/stream.h
==============================================================================
--- trunk/stream/stream.h Sun Feb 28 13:54:12 2010 (r30795)
+++ trunk/stream/stream.h Sun Feb 28 14:54:55 2010 (r30796)
@@ -265,32 +265,7 @@ inline static int stream_read(stream_t *
return total;
}
-inline static unsigned char* stream_read_line(stream_t *s,unsigned char* mem, int max) {
- int len;
- unsigned char* end,*ptr = mem;
- if (max < 1) return NULL;
- max--; // reserve one for 0-termination
- do {
- len = s->buf_len-s->buf_pos;
- // try to fill the buffer
- if(len <= 0 &&
- (!cache_stream_fill_buffer(s) ||
- (len = s->buf_len-s->buf_pos) <= 0)) break;
- end = (unsigned char*) memchr((void*)(s->buffer+s->buf_pos),'\n',len);
- if(end) len = end - (s->buffer+s->buf_pos) + 1;
- if(len > 0 && max > 0) {
- int l = len > max ? max : len;
- memcpy(ptr,s->buffer+s->buf_pos,l);
- max -= l;
- ptr += l;
- }
- s->buf_pos += len;
- } while(!end);
- if(s->eof && ptr == mem) return NULL;
- ptr[0] = 0;
- return mem;
-}
-
+unsigned char* stream_read_line(stream_t *s,unsigned char* mem, int max);
inline static int stream_eof(stream_t *s){
return s->eof;
More information about the MPlayer-cvslog
mailing list