Mercurial > libavutil.hg
comparison fifo.c @ 230:4c85ac99ab37 libavutil
change while loops to do-while as the condition is true the first time and the check just wastes cpu cycles
author | michael |
---|---|
date | Thu, 18 Jan 2007 00:22:24 +0000 |
parents | 3f5c648b82c4 |
children | 75f096258d14 |
comparison
equal
deleted
inserted
replaced
229:3f5c648b82c4 | 230:4c85ac99ab37 |
---|---|
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size) | 74 void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size) |
75 { | 75 { |
76 while (size > 0) { | 76 do { |
77 int len = FFMIN(f->end - f->wptr, size); | 77 int len = FFMIN(f->end - f->wptr, size); |
78 memcpy(f->wptr, buf, len); | 78 memcpy(f->wptr, buf, len); |
79 f->wptr += len; | 79 f->wptr += len; |
80 if (f->wptr >= f->end) | 80 if (f->wptr >= f->end) |
81 f->wptr = f->buffer; | 81 f->wptr = f->buffer; |
82 buf += len; | 82 buf += len; |
83 size -= len; | 83 size -= len; |
84 } | 84 } while (size > 0); |
85 } | 85 } |
86 | 86 |
87 | 87 |
88 /** get data from the fifo (return -1 if not enough data) */ | 88 /** get data from the fifo (return -1 if not enough data) */ |
89 int av_fifo_generic_read(AVFifoBuffer *f, int buf_size, void (*func)(void*, void*, int), void* dest) | 89 int av_fifo_generic_read(AVFifoBuffer *f, int buf_size, void (*func)(void*, void*, int), void* dest) |
90 { | 90 { |
91 int size = av_fifo_size(f); | 91 int size = av_fifo_size(f); |
92 | 92 |
93 if (size < buf_size) | 93 if (size < buf_size) |
94 return -1; | 94 return -1; |
95 while (buf_size > 0) { | 95 do { |
96 int len = FFMIN(f->end - f->rptr, buf_size); | 96 int len = FFMIN(f->end - f->rptr, buf_size); |
97 if(func) func(dest, f->rptr, len); | 97 if(func) func(dest, f->rptr, len); |
98 else{ | 98 else{ |
99 memcpy(dest, f->rptr, len); | 99 memcpy(dest, f->rptr, len); |
100 dest = (uint8_t*)dest + len; | 100 dest = (uint8_t*)dest + len; |
101 } | 101 } |
102 av_fifo_drain(f, len); | 102 av_fifo_drain(f, len); |
103 buf_size -= len; | 103 buf_size -= len; |
104 } | 104 } while (buf_size > 0); |
105 return 0; | 105 return 0; |
106 } | 106 } |
107 | 107 |
108 /** discard data from the fifo */ | 108 /** discard data from the fifo */ |
109 void av_fifo_drain(AVFifoBuffer *f, int size) | 109 void av_fifo_drain(AVFifoBuffer *f, int size) |