[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/filters
From:       Thorsten Zachmann <t.zachmann () zagge ! de>
Date:       2010-10-29 7:30:26
Message-ID: 20101029073027.0538CAC899 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1190847 by zachmann:

Optimize pole to don't use new/delete but a buffer on the stack.

That removes quite some new/delete calls.

Reviewed by Mek


 M  +7 -10     kspread/excel/sidewinder/pole.cpp  
 M  +7 -10     kword/hancomword/pole.cpp  
 M  +7 -10     kword/starwriter/pole.cpp  
 M  +7 -10     libmso/pole.cpp  
 M  +7 -10     libmsooxml/pole.cpp  


--- trunk/koffice/filters/kspread/excel/sidewinder/pole.cpp #1190846:1190847
@@ -269,7 +269,7 @@
     if ((num_bat < 109) && (num_mbat != 0)) return false;
     if (s_shift > b_shift) return false;
     if (b_shift <= 6) return false;
-    if (b_shift >= 31) return false;
+    if (b_shift > 12) return false;
 
     return true;
 }
@@ -1171,19 +1171,18 @@
 
         if (index >= blocks.size()) return 0;
 
-        unsigned char* buf = new unsigned char[ io->sbat->blockSize ];
+        unsigned char buf[4096];
         unsigned long offset = pos % io->sbat->blockSize;
         while (totalbytes < maxlen) {
             if (index >= blocks.size()) break;
-            io->loadSmallBlock(blocks[index], buf, io->bbat->blockSize);
+            io->loadSmallBlock(blocks[index], &buf[0], io->bbat->blockSize);
             unsigned long count = io->sbat->blockSize - offset;
             if (count > maxlen - totalbytes) count = maxlen - totalbytes;
-            memcpy(data + totalbytes, buf + offset, count);
+            memcpy(data + totalbytes, &buf[0] + offset, count);
             totalbytes += count;
             offset = 0;
             index++;
         }
-        delete[] buf;
 
     } else {
         // big file
@@ -1191,23 +1190,21 @@
 
         if (index >= blocks.size()) return 0;
 
-        unsigned char* buf = new unsigned char[ io->bbat->blockSize ];
+        unsigned char buf[4096];
         unsigned long offset = pos % io->bbat->blockSize;
         while (totalbytes < maxlen) {
             if (index >= blocks.size()) break;
-            unsigned long r = io->loadBigBlock(blocks[index], buf, io->bbat->blockSize);
+            unsigned long r = io->loadBigBlock(blocks[index], &buf[0], io->bbat->blockSize);
             if (r != io->bbat->blockSize) {
-                delete [] buf;
                 return 0;
             }
             unsigned long count = io->bbat->blockSize - offset;
             if (count > maxlen - totalbytes) count = maxlen - totalbytes;
-            memcpy(data + totalbytes, buf + offset, count);
+            memcpy(data + totalbytes, &buf[0] + offset, count);
             totalbytes += count;
             index++;
             offset = 0;
         }
-        delete [] buf;
 
     }
 
--- trunk/koffice/filters/kword/hancomword/pole.cpp #1190846:1190847
@@ -267,7 +267,7 @@
     if ((num_bat < 109) && (num_mbat != 0)) return false;
     if (s_shift > b_shift) return false;
     if (b_shift <= 6) return false;
-    if (b_shift >= 31) return false;
+    if (b_shift > 12) return false;
 
     return true;
 }
@@ -1165,19 +1165,18 @@
 
         if (index >= blocks.size()) return 0;
 
-        unsigned char* buf = new unsigned char[ io->sbat->blockSize ];
+        unsigned char buf[4096];
         unsigned long offset = pos % io->sbat->blockSize;
         while (totalbytes < maxlen) {
             if (index >= blocks.size()) break;
-            io->loadSmallBlock(blocks[index], buf, io->bbat->blockSize);
+            io->loadSmallBlock(blocks[index], &buf[0], io->bbat->blockSize);
             unsigned long count = io->sbat->blockSize - offset;
             if (count > maxlen - totalbytes) count = maxlen - totalbytes;
-            memcpy(data + totalbytes, buf + offset, count);
+            memcpy(data + totalbytes, &buf[0] + offset, count);
             totalbytes += count;
             offset = 0;
             index++;
         }
-        delete[] buf;
 
     } else {
         // big file
@@ -1185,23 +1184,21 @@
 
         if (index >= blocks.size()) return 0;
 
-        unsigned char* buf = new unsigned char[ io->bbat->blockSize ];
+        unsigned char buf[4096];
         unsigned long offset = pos % io->bbat->blockSize;
         while (totalbytes < maxlen) {
             if (index >= blocks.size()) break;
-            unsigned long r = io->loadBigBlock(blocks[index], buf, io->bbat->blockSize);
+            unsigned long r = io->loadBigBlock(blocks[index], &buf[0], io->bbat->blockSize);
             if (r != io->bbat->blockSize) {
-                delete [] buf;
                 return 0;
             }
             unsigned long count = io->bbat->blockSize - offset;
             if (count > maxlen - totalbytes) count = maxlen - totalbytes;
-            memcpy(data + totalbytes, buf + offset, count);
+            memcpy(data + totalbytes, &buf[0] + offset, count);
             totalbytes += count;
             index++;
             offset = 0;
         }
-        delete [] buf;
 
     }
 
--- trunk/koffice/filters/kword/starwriter/pole.cpp #1190846:1190847
@@ -267,7 +267,7 @@
     if ((num_bat < 109) && (num_mbat != 0)) return false;
     if (s_shift > b_shift) return false;
     if (b_shift <= 6) return false;
-    if (b_shift >= 31) return false;
+    if (b_shift > 12) return false;
 
     return true;
 }
@@ -1165,19 +1165,18 @@
 
         if (index >= blocks.size()) return 0;
 
-        unsigned char* buf = new unsigned char[ io->sbat->blockSize ];
+        unsigned char buf[4096];
         unsigned long offset = pos % io->sbat->blockSize;
         while (totalbytes < maxlen) {
             if (index >= blocks.size()) break;
-            io->loadSmallBlock(blocks[index], buf, io->bbat->blockSize);
+            io->loadSmallBlock(blocks[index], &buf[0], io->bbat->blockSize);
             unsigned long count = io->sbat->blockSize - offset;
             if (count > maxlen - totalbytes) count = maxlen - totalbytes;
-            memcpy(data + totalbytes, buf + offset, count);
+            memcpy(data + totalbytes, &buf[0] + offset, count);
             totalbytes += count;
             offset = 0;
             index++;
         }
-        delete[] buf;
 
     } else {
         // big file
@@ -1185,23 +1184,21 @@
 
         if (index >= blocks.size()) return 0;
 
-        unsigned char* buf = new unsigned char[ io->bbat->blockSize ];
+        unsigned char buf[4096];
         unsigned long offset = pos % io->bbat->blockSize;
         while (totalbytes < maxlen) {
             if (index >= blocks.size()) break;
-            unsigned long r = io->loadBigBlock(blocks[index], buf, io->bbat->blockSize);
+            unsigned long r = io->loadBigBlock(blocks[index], &buf[0], io->bbat->blockSize);
             if (r != io->bbat->blockSize) {
-                delete [] buf;
                 return 0;
             }
             unsigned long count = io->bbat->blockSize - offset;
             if (count > maxlen - totalbytes) count = maxlen - totalbytes;
-            memcpy(data + totalbytes, buf + offset, count);
+            memcpy(data + totalbytes, &buf[0] + offset, count);
             totalbytes += count;
             index++;
             offset = 0;
         }
-        delete [] buf;
 
     }
 
--- trunk/koffice/filters/libmso/pole.cpp #1190846:1190847
@@ -267,7 +267,7 @@
     if ((num_bat < 109) && (num_mbat != 0)) return false;
     if (s_shift > b_shift) return false;
     if (b_shift <= 6) return false;
-    if (b_shift >= 31) return false;
+    if (b_shift > 12) return false;
 
     return true;
 }
@@ -1166,19 +1166,18 @@
 
         if (index >= blocks.size()) return 0;
 
-        unsigned char* buf = new unsigned char[ io->sbat->blockSize ];
+        unsigned char buf[4096];
         unsigned long offset = pos % io->sbat->blockSize;
         while (totalbytes < maxlen) {
             if (index >= blocks.size()) break;
-            io->loadSmallBlock(blocks[index], buf, io->bbat->blockSize);
+            io->loadSmallBlock(blocks[index], &buf[0], io->bbat->blockSize);
             unsigned long count = io->sbat->blockSize - offset;
             if (count > maxlen - totalbytes) count = maxlen - totalbytes;
-            memcpy(data + totalbytes, buf + offset, count);
+            memcpy(data + totalbytes, &buf[0] + offset, count);
             totalbytes += count;
             offset = 0;
             index++;
         }
-        delete[] buf;
 
     } else {
         // big file
@@ -1186,23 +1185,21 @@
 
         if (index >= blocks.size()) return 0;
 
-        unsigned char* buf = new unsigned char[ io->bbat->blockSize ];
+        unsigned char buf[4096];
         unsigned long offset = pos % io->bbat->blockSize;
         while (totalbytes < maxlen) {
             if (index >= blocks.size()) break;
-            unsigned long r = io->loadBigBlock(blocks[index], buf, io->bbat->blockSize);
+            unsigned long r = io->loadBigBlock(blocks[index], &buf[0], io->bbat->blockSize);
             if (r != io->bbat->blockSize) {
-                delete [] buf;
                 return 0;
             }
             unsigned long count = io->bbat->blockSize - offset;
             if (count > maxlen - totalbytes) count = maxlen - totalbytes;
-            memcpy(data + totalbytes, buf + offset, count);
+            memcpy(data + totalbytes, &buf[0] + offset, count);
             totalbytes += count;
             index++;
             offset = 0;
         }
-        delete [] buf;
 
     }
 
--- trunk/koffice/filters/libmsooxml/pole.cpp #1190846:1190847
@@ -270,7 +270,7 @@
     if ((num_bat < 109) && (num_mbat != 0)) return false;
     if (s_shift > b_shift) return false;
     if (b_shift <= 6) return false;
-    if (b_shift >= 31) return false;
+    if (b_shift > 12) return false;
 
     return true;
 }
@@ -1180,19 +1180,18 @@
 
         if (index >= blocks.size()) return 0;
 
-        unsigned char* buf = new unsigned char[ io->sbat->blockSize ];
+        unsigned char buf[4096];
         unsigned long offset = pos % io->sbat->blockSize;
         while (totalbytes < maxlen) {
             if (index >= blocks.size()) break;
-            io->loadSmallBlock(blocks[index], buf, io->bbat->blockSize);
+            io->loadSmallBlock(blocks[index], &buf[0], io->bbat->blockSize);
             unsigned long count = io->sbat->blockSize - offset;
             if (count > maxlen - totalbytes) count = maxlen - totalbytes;
-            memcpy(data + totalbytes, buf + offset, count);
+            memcpy(data + totalbytes, &buf[0] + offset, count);
             totalbytes += count;
             offset = 0;
             index++;
         }
-        delete[] buf;
 
     } else {
         // big file
@@ -1200,23 +1199,21 @@
 
         if (index >= blocks.size()) return 0;
 
-        unsigned char* buf = new unsigned char[ io->bbat->blockSize ];
+        unsigned char buf[4096];
         unsigned long offset = pos % io->bbat->blockSize;
         while (totalbytes < maxlen) {
             if (index >= blocks.size()) break;
-            unsigned long r = io->loadBigBlock(blocks[index], buf, io->bbat->blockSize);
+            unsigned long r = io->loadBigBlock(blocks[index], &buf[0], io->bbat->blockSize);
             if (r != io->bbat->blockSize) {
-                delete [] buf;
                 return 0;
             }
             unsigned long count = io->bbat->blockSize - offset;
             if (count > maxlen - totalbytes) count = maxlen - totalbytes;
-            memcpy(data + totalbytes, buf + offset, count);
+            memcpy(data + totalbytes, &buf[0] + offset, count);
             totalbytes += count;
             index++;
             offset = 0;
         }
-        delete [] buf;
 
     }
 
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic