[vorbis-dev] First patch, little speed up... (about 1%)

vitorsessak at osite.com.br vitorsessak at osite.com.br
Fri Jun 30 15:29:07 PDT 2000



I did optimized a bit an loop at psy.c (by the way, the code looks quite more beautiful now)   ;-)
Have a look...

--- psy.c       Sat Jun 24 12:09:23 2000
+++ -           Fri Jun 30 19:03:37 2000
@@ -452,38 +452,38 @@

 /* bleaugh, this is more complicated than it needs to be */
 static void max_seeds(vorbis_look_psy *p,double *flr){
   long n=p->n,i,j;
-  long *posstack=alloca(n*sizeof(long));
-  double *ampstack=alloca(n*sizeof(double));
-  long stack=0;
+  long *posstack=alloca((n+1)*sizeof(long));
+  double *ampstack=alloca((n+1)*sizeof(double));
+  long stack=2;

-  for(i=0;i<n;i++){
-    if(stack<2){
-      posstack[stack]=i;
-      ampstack[stack++]=flr[i];
-    }else{
+  posstack[0]=0;
+  ampstack[0]=flr[0];
+  posstack[1]=1;
+  ampstack[1]=flr[1];
+
+
+  for(i=2;i<n;i++){
+    if (flr[i]>=ampstack[stack-1])
       while(1){
-       if(flr[i]<ampstack[stack-1]){
-         posstack[stack]=i;
-         ampstack[stack++]=flr[i];
-         break;
-       }else{
-         if(i<posstack[stack-1]*1.0905077080){
-           if(stack>1 && ampstack[stack-1]<ampstack[stack-2] &&
-              i<posstack[stack-2]*1.0905077080){
-             /* we completely overlap, making stack-1 irrelevant.  pop it */
-             stack--;
-             continue;
+       if(i<posstack[stack-1]*1.0905077080)
+         if(stack>1 && ampstack[stack-1]<ampstack[stack-2] &&
+            i<posstack[stack-2]*1.0905077080){
+           /* we completely overlap, making stack-1 irrelevant.  pop it */
+           stack--;
+           if(flr[i]<ampstack[stack-1]){
+             if(stack<2){
+               i++;
+             }
+             break;
            }
-         }
-         posstack[stack]=i;
-         ampstack[stack++]=flr[i];
-         break;
-
+         continue;
        }
-      }
+      break;
     }
+    posstack[stack]=i;
+    ampstack[stack++]=flr[i];
   }

   /* the stack now contains only the positions that are relevant. Scan
      'em straight through */

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/



More information about the Vorbis-dev mailing list