summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2005-05-28 14:19:16 +0200
committerKlaus Schmidinger <vdr@tvdr.de>2005-05-28 14:19:16 +0200
commit1e63fa4174c73d8ea4d257b883a9ac926a87311d (patch)
tree130f5125303bb9f1192cab935f659f3b6855a911
parentae3da0bcec271892b4e4aa1c34a0eb06c3856035 (diff)
downloadvdr-1e63fa4174c73d8ea4d257b883a9ac926a87311d.tar.gz
vdr-1e63fa4174c73d8ea4d257b883a9ac926a87311d.tar.bz2
Avoiding unnecessary calls to getLength() in libsi/si.c, and avoiding the '& 0xff' in CRC32::crc32() of libsi/util.c
-rw-r--r--CONTRIBUTORS2
-rw-r--r--HISTORY2
-rw-r--r--libsi/si.c35
-rw-r--r--libsi/util.c5
4 files changed, 28 insertions, 16 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 7e1a22d0..96d21c65 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -1362,3 +1362,5 @@ Georg Acher <acher@baycom.de>
for making tChannelID::operator==() inline for better performance
for introducing cListBase::count for better performance
for a patch that was used to implement hash tables to speed up cSchedule::GetEvent()
+ for avoiding unnecessary calls to getLength() in libsi/si.c, and avoiding the
+ '& 0xff' in CRC32::crc32() of libsi/util.c
diff --git a/HISTORY b/HISTORY
index 1bca9213..c2ebcaa7 100644
--- a/HISTORY
+++ b/HISTORY
@@ -3570,3 +3570,5 @@ Video Disk Recorder Revision History
the schedule it is in.
- Now using hash tables to speed up cSchedule::GetEvent() (partially based on
a patch from Georg Acher).
+- Avoiding unnecessary calls to getLength() in libsi/si.c, and avoiding the
+ '& 0xff' in CRC32::crc32() of libsi/util.c (thanks to Georg Acher).
diff --git a/libsi/si.c b/libsi/si.c
index ba97c6e9..90d40303 100644
--- a/libsi/si.c
+++ b/libsi/si.c
@@ -6,7 +6,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
- * $Id: si.c 1.13 2004/10/16 15:12:57 kls Exp $
+ * $Id: si.c 1.14 2005/05/28 14:11:16 kls Exp $
* *
***************************************************************************/
@@ -114,9 +114,10 @@ Descriptor *DescriptorLoop::getNext(Iterator &it) {
Descriptor *DescriptorLoop::getNext(Iterator &it, DescriptorTag tag, bool returnUnimplemetedDescriptor) {
Descriptor *d=0;
- if (isValid() && it.i<getLength()) {
+ int len;
+ if (isValid() && it.i<(len=getLength())) {
const unsigned char *p=data.getData(it.i);
- const unsigned char *end=p+getLength()-it.i;
+ const unsigned char *end=p+len-it.i;
while (p < end) {
if (Descriptor::getDescriptorTag(p) == tag) {
d=createDescriptor(it.i, returnUnimplemetedDescriptor);
@@ -132,9 +133,10 @@ Descriptor *DescriptorLoop::getNext(Iterator &it, DescriptorTag tag, bool return
Descriptor *DescriptorLoop::getNext(Iterator &it, DescriptorTag *tags, int arrayLength, bool returnUnimplementedDescriptor) {
Descriptor *d=0;
- if (isValid() && it.i<getLength()) {
+ int len;
+ if (isValid() && it.i<(len=getLength())) {
const unsigned char *p=data.getData(it.i);
- const unsigned char *end=p+getLength()-it.i;
+ const unsigned char *end=p+len-it.i;
while (p < end) {
for (int u=0; u<arrayLength;u++)
if (Descriptor::getDescriptorTag(p) == tags[u]) {
@@ -211,15 +213,17 @@ bool DescriptorGroup::isComplete() {
}
char *String::getText() {
- if (getLength() < 0 || getLength() >4095)
+ int len=getLength();
+ if (len < 0 || len > 4095)
return strdup("text error"); // caller will delete it!
- char *data=new char(getLength()+1);
- decodeText(data, getLength()+1);
+ char *data=new char(len+1);
+ decodeText(data, len+1);
return data;
}
char *String::getText(char *buffer, int size) {
- if (getLength() < 0 || getLength() >= size) {
+ int len=getLength();
+ if (len < 0 || len >= size) {
strncpy(buffer, "text error", size);
buffer[size-1] = 0;
return buffer;
@@ -230,7 +234,8 @@ char *String::getText(char *buffer, int size) {
//taken from VDR, Copyright Klaus Schmidinger <kls@cadsoft.de>
char *String::getText(char *buffer, char *shortVersion, int sizeBuffer, int sizeShortVersion) {
- if (getLength() < 0 || getLength() >= sizeBuffer) {
+ int len=getLength();
+ if (len < 0 || len >= sizeBuffer) {
strncpy(buffer, "text error", sizeBuffer);
buffer[sizeBuffer-1] = 0;
*shortVersion = 0;
@@ -254,7 +259,8 @@ void String::decodeText(char *buffer, int size) {
if (*from == 0x10)
from += 3; // skips code table info
- for (int i = 0; i < getLength(); i++) {
+ int len=getLength();
+ for (int i = 0; i < len; i++) {
if (*from == 0)
break;
if ( ((' ' <= *from) && (*from <= '~'))
@@ -281,9 +287,8 @@ void String::decodeText(char *buffer, char *shortVersion, int sizeBuffer, int si
if (*from == 0x10)
from += 3; // skips code table info
- for (int i = 0; i < getLength(); i++) {
- if (*from == 0)
- break;
+ int len=getLength();
+ for (int i = 0; i < len; i++) {
if ( ((' ' <= *from) && (*from <= '~'))
|| (*from == '\n')
|| (0xA0 <= *from)
@@ -299,6 +304,8 @@ void String::decodeText(char *buffer, char *shortVersion, int sizeBuffer, int si
IsShortName++;
else if (*from == 0x87)
IsShortName--;
+ else if (*from == 0)
+ break;
from++;
if (to - buffer >= sizeBuffer - 1 || toShort - shortVersion >= sizeShortVersion - 1)
break;
diff --git a/libsi/util.c b/libsi/util.c
index c6ad234a..34657948 100644
--- a/libsi/util.c
+++ b/libsi/util.c
@@ -6,7 +6,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
- * $Id: util.c 1.4 2004/10/16 09:58:41 kls Exp $
+ * $Id: util.c 1.5 2005/05/28 14:15:29 kls Exp $
* *
***************************************************************************/
@@ -263,9 +263,10 @@ u_int32_t CRC32::crc_table[256] = {
u_int32_t CRC32::crc32 (const char *d, int len, u_int32_t crc)
{
register int i;
+ const unsigned char *u=(unsigned char*)d; // Saves '& 0xff'
for (i=0; i<len; i++)
- crc = (crc << 8) ^ crc_table[((crc >> 24) ^ *d++) & 0xff];
+ crc = (crc << 8) ^ crc_table[((crc >> 24) ^ *u++)];
return crc;
}