CVSROOT: /sources/gnash Module name: gnash Changes by: Sandro Santilli <strk> 07/08/27 12:09:06
Modified files: . : ChangeLog server : stream.cpp stream.h server/parser : shape_character_def.cpp testsuite/server: StreamTest.cpp Log message: * server/stream.{cpp,h}: add read_bit(), optimize read_uint() a little-bit (there are likely more optimization options). * server/parser/shape_character_def.cpp (read): use read_bit() instead of read_uint(1). * testsuite/server/StreamTest.cpp: more tests for read_bit(). CVSWeb URLs: http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.4114&r2=1.4115 http://cvs.savannah.gnu.org/viewcvs/gnash/server/stream.cpp?cvsroot=gnash&r1=1.26&r2=1.27 http://cvs.savannah.gnu.org/viewcvs/gnash/server/stream.h?cvsroot=gnash&r1=1.25&r2=1.26 http://cvs.savannah.gnu.org/viewcvs/gnash/server/parser/shape_character_def.cpp?cvsroot=gnash&r1=1.33&r2=1.34 http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/server/StreamTest.cpp?cvsroot=gnash&r1=1.2&r2=1.3 Patches: Index: ChangeLog =================================================================== RCS file: /sources/gnash/gnash/ChangeLog,v retrieving revision 1.4114 retrieving revision 1.4115 diff -u -b -r1.4114 -r1.4115 --- ChangeLog 27 Aug 2007 11:58:46 -0000 1.4114 +++ ChangeLog 27 Aug 2007 12:09:04 -0000 1.4115 @@ -1,3 +1,11 @@ +2007-08-27 Sandro Santilli <[EMAIL PROTECTED]> + + * server/stream.{cpp,h}: add read_bit(), optimize read_uint() + a little-bit (there are likely more optimization options). + * server/parser/shape_character_def.cpp (read): use read_bit() + instead of read_uint(1). + * testsuite/server/StreamTest.cpp: more tests for read_bit(). + 2007-08-27 Markus Gothe <[EMAIL PROTECTED]> * libbase/utility.h: defined exp2() as it's missing on some BSDen. Index: server/stream.cpp =================================================================== RCS file: /sources/gnash/gnash/server/stream.cpp,v retrieving revision 1.26 retrieving revision 1.27 diff -u -b -r1.26 -r1.27 --- server/stream.cpp 27 Aug 2007 03:06:41 -0000 1.26 +++ server/stream.cpp 27 Aug 2007 12:09:05 -0000 1.27 @@ -54,44 +54,71 @@ // } + bool stream::read_bit() + { + if (!m_unused_bits) + { + m_current_byte = m_input->read_byte(); + m_unused_bits = 7; + return (m_current_byte&0x80); + } + else + { + return ( m_current_byte & (1<<(--m_unused_bits)) ); + } + } + unsigned stream::read_uint(unsigned short bitcount) { - assert(bitcount <= 32); + assert(bitcount <= 24); + + if (!m_unused_bits) + { + m_current_byte = m_input->read_byte(); + m_unused_bits = 8; + } uint32_t value = 0; unsigned short bits_needed = bitcount; - while (bits_needed > 0) + do + { + // TODO: cache this mask instead of m_unused_bits ? + int unusedMask = (1 << m_unused_bits)-1; + + if (bits_needed == m_unused_bits) { - if (m_unused_bits) { - if (bits_needed >= m_unused_bits) { // Consume all the unused bits. - value |= (m_current_byte << (bits_needed - m_unused_bits)); + value |= (m_current_byte&unusedMask); + m_unused_bits = 0; + break; - bits_needed -= m_unused_bits; + } + else if (bits_needed > m_unused_bits) + { + // Consume all the unused bits. - m_current_byte = 0; - m_unused_bits = 0; + bits_needed -= m_unused_bits; // assert(bits_needed>0) - } else { - // Consume some of the unused bits. - value |= (m_current_byte >> (m_unused_bits - bits_needed)); + value |= ((m_current_byte&unusedMask) << bits_needed); - // mask off the bits we consumed. - m_current_byte &= ((1 << (m_unused_bits - bits_needed)) - 1); + m_current_byte = m_input->read_byte(); + m_unused_bits = 8; + + } + else + { + // Consume some of the unused bits. m_unused_bits -= bits_needed; + value |= ((m_current_byte&unusedMask) >> m_unused_bits); + // We're done. - bits_needed = 0; + break; } - } else { - m_current_byte = m_input->read_byte(); - m_unused_bits = 8; } - } - - assert(bits_needed == 0); + while (bits_needed > 0); return value; } Index: server/stream.h =================================================================== RCS file: /sources/gnash/gnash/server/stream.h,v retrieving revision 1.25 retrieving revision 1.26 diff -u -b -r1.25 -r1.26 --- server/stream.h 26 Aug 2007 15:14:12 -0000 1.25 +++ server/stream.h 27 Aug 2007 12:09:05 -0000 1.26 @@ -46,6 +46,11 @@ unsigned read_uint(unsigned short bitcount); /// \brief + /// Reads a single bit off the stream + /// and returns it. + bool read_bit(); + + /// \brief /// Reads a bit-packed little-endian signed integer /// from the stream. The given bitcount determines the /// number of bits to read. Index: server/parser/shape_character_def.cpp =================================================================== RCS file: /sources/gnash/gnash/server/parser/shape_character_def.cpp,v retrieving revision 1.33 retrieving revision 1.34 diff -u -b -r1.33 -r1.34 --- server/parser/shape_character_def.cpp 23 Aug 2007 15:10:51 -0000 1.33 +++ server/parser/shape_character_def.cpp 27 Aug 2007 12:09:05 -0000 1.34 @@ -17,7 +17,7 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // -/* $Id: shape_character_def.cpp,v 1.33 2007/08/23 15:10:51 strk Exp $ */ +/* $Id: shape_character_def.cpp,v 1.34 2007/08/27 12:09:05 strk Exp $ */ // Based on the public domain shape.cpp of Thatcher Ulrich <[EMAIL PROTECTED]> 2003 @@ -226,8 +226,8 @@ // SHAPERECORDS for (;;) { - int type_flag = in->read_uint(1); - if (type_flag == 0) { + bool isEdgeRecord = in->read_bit(); + if (!isEdgeRecord) { // Parse the record. int flags = in->read_uint(5); if (flags == flagEnd) { @@ -430,7 +430,7 @@ } } else { // EDGERECORD - int edge_flag = in->read_uint(1); + bool edge_flag = in->read_bit(); if (edge_flag == 0) { // curved edge int num_bits = 2 + in->read_uint(4); @@ -453,14 +453,14 @@ } else { // straight edge int num_bits = 2 + in->read_uint(4); - int line_flag = in->read_uint(1); + bool line_flag = in->read_bit(); float dx = 0, dy = 0; if (line_flag) { // General line. dx = (float) in->read_sint(num_bits); dy = (float) in->read_sint(num_bits); } else { - int vert_flag = in->read_uint(1); + bool vert_flag = in->read_bit(); if (vert_flag == 0) { // Horizontal line. dx = (float) in->read_sint(num_bits); Index: testsuite/server/StreamTest.cpp =================================================================== RCS file: /sources/gnash/gnash/testsuite/server/StreamTest.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -b -r1.2 -r1.3 --- testsuite/server/StreamTest.cpp 27 Aug 2007 08:28:42 -0000 1.2 +++ testsuite/server/StreamTest.cpp 27 Aug 2007 12:09:05 -0000 1.3 @@ -57,6 +57,11 @@ b(by) {} + void setByte(unsigned char by) + { + b=by; + } + static int readFunc(void* dst, int bytes, void* appdata) { assert(bytes == 1); @@ -97,10 +102,6 @@ ret = s.read_uint(1); check_equals(ret, 0); ret = s.read_uint(1); check_equals(ret, 1); ret = s.read_uint(1); check_equals(ret, 0); - - /// bits: 10101010 (0xAA) - - s.align(); ret = s.read_uint(1); check_equals(ret, 1); ret = s.read_uint(1); check_equals(ret, 0); ret = s.read_uint(1); check_equals(ret, 1); @@ -213,6 +214,39 @@ s.align(); ret = s.read_uint(24); check_equals(ret, 11184810); + /// bits: 1010101010101010 (0xAAAA) + + s.align(); + ret = s.read_bit(); check_equals(ret, 1); + ret = s.read_bit(); check_equals(ret, 0); + ret = s.read_bit(); check_equals(ret, 1); + ret = s.read_bit(); check_equals(ret, 0); + ret = s.read_bit(); check_equals(ret, 1); + ret = s.read_bit(); check_equals(ret, 0); + ret = s.read_bit(); check_equals(ret, 1); + ret = s.read_bit(); check_equals(ret, 0); + ret = s.read_bit(); check_equals(ret, 1); + ret = s.read_bit(); check_equals(ret, 0); + ret = s.read_bit(); check_equals(ret, 1); + ret = s.read_bit(); check_equals(ret, 0); + ret = s.read_bit(); check_equals(ret, 1); + ret = s.read_bit(); check_equals(ret, 0); + ret = s.read_bit(); check_equals(ret, 1); + ret = s.read_bit(); check_equals(ret, 0); + + /// bits: 10011001 (0x99) + + br.setByte(0x99); + s.align(); + ret = s.read_bit(); check_equals(ret, 1); + ret = s.read_bit(); check_equals(ret, 0); + ret = s.read_bit(); check_equals(ret, 0); + ret = s.read_bit(); check_equals(ret, 1); + ret = s.read_bit(); check_equals(ret, 1); + ret = s.read_bit(); check_equals(ret, 0); + ret = s.read_bit(); check_equals(ret, 0); + ret = s.read_bit(); check_equals(ret, 1); + return 0; } _______________________________________________ Gnash-commit mailing list Gnash-commit@gnu.org http://lists.gnu.org/mailman/listinfo/gnash-commit