Retract #15745 for now; won't work without more Encode fixes.
[p5sagit/p5-mst-13.2.git] / ext / Encode / Encode.xs
index 1152c7a..741b679 100644 (file)
@@ -7,12 +7,12 @@
 #include "def_t.h"
 
 #define ENCODE_XS_PROFILE 0 /* set 1 to profile.
-                              t/encoding.t dumps core because of
-                              Perl_warner and PerlIO don't work well */
+                              t/encoding.t dumps core because of
+                              Perl_warner and PerlIO don't work well */
 
 #define ENCODE_XS_USEFP   1 /* set 0 to disable floating point to calculate
-                              buffer size for encode_method().
-                              1 is recommended. 2 restores NI-S original  */
+                              buffer size for encode_method().
+                              1 is recommended. 2 restores NI-S original  */
 
 #define UNIMPLEMENTED(x,y) y x (SV *sv, char *encoding) {dTHX;   \
                          Perl_croak(aTHX_ "panic_unimplemented"); \
@@ -499,9 +499,9 @@ encode_method(pTHX_ encode_t * enc, encpage_t * dir, SV * src,
     STRLEN ddone = 0;
     STRLEN sdone = 0;
 
-   /* We allocate slen+1.
-      PerlIO dumps core if this value is smaller than this. */
-    SV *dst = sv_2mortal(newSV(slen+1));
+    /* We allocate slen+1.  
+        PerlIO dumps core if this value is smaller than this. */
+    SV *dst = sv_2mortal(newSV(slen+1)); 
     if (slen) {
        U8 *d = (U8 *) SvPVX(dst);
        STRLEN dlen = SvLEN(dst)-1;
@@ -519,28 +519,27 @@ encode_method(pTHX_ encode_t * enc, encpage_t * dir, SV * src,
 
            switch (code) {
            case ENCODE_NOSPACE:
-           {
+           {   
                    STRLEN more, sleft;
                    sdone += slen;
                    ddone += dlen;
                    sleft = tlen - sdone;
                    if (sdone) { /* has src ever been processed ? */
 #if   ENCODE_XS_USEFP == 2
-                           more = (1.0*tlen*SvLEN(dst)+sdone-1)/sdone
-                                   - SvLEN(dst);
+                           more = (1.0*tlen*SvLEN(dst)+sdone-1)/sdone
+                                   - SvLEN(dst);
 #elif ENCODE_XS_USEFP
-                           more = (1.0*SvLEN(dst)+1)/sdone * sleft;
+                           more = (1.0*SvLEN(dst)+1)/sdone * sleft;
 #else
-                           /* safe until SvLEN(dst) == MAX_INT/16 */
-                           more = (16*SvLEN(dst)+1)/sdone/16 * sleft;
+                           /* safe until SvLEN(dst) == MAX_INT/16 */
+                           more = (16*SvLEN(dst)+1)/sdone/16 * sleft;
 #endif
                    }
-               
                    more += UTF8_MAXLEN; /* insurance policy */
 #if ENCODE_XS_PROFILE >= 2
-                   Perl_warn(aTHX_
-                             "more=%d, sdone=%d, sleft=%d, SvLEN(dst)=%d\n",
-                             more, sdone, sleft, SvLEN(dst));
+                 Perl_warn(aTHX_ 
+                 "more=%d, sdone=%d, sleft=%d, SvLEN(dst)=%d\n",
+                           more, sdone, sleft, SvLEN(dst));
 #endif
                    d = (U8 *) SvGROW(dst, SvLEN(dst) + more);
                    /* dst need to grow need MORE bytes! */
@@ -615,14 +614,14 @@ encode_method(pTHX_ encode_t * enc, encpage_t * dir, SV * src,
     }
 #if ENCODE_XS_PROFILE
     if (SvCUR(dst) > SvCUR(src)){
-           Perl_warn(aTHX_
-                     "SvLEN(dst)=%d, SvCUR(dst)=%d. "
-                     "%d bytes unused(%f %%)\n",
-                     SvLEN(dst), SvCUR(dst), SvLEN(dst) - SvCUR(dst),
-                     (SvLEN(dst) - SvCUR(dst))*1.0/SvLEN(dst)*100.0);
-
+           Perl_warn(aTHX_ 
+                     "SvLEN(dst)=%d, SvCUR(dst)=%d. "
+                     "%d bytes unused(%f %%)\n",
+                     SvLEN(dst), SvCUR(dst), SvLEN(dst) - SvCUR(dst), 
+                     (SvLEN(dst) - SvCUR(dst))*1.0/SvLEN(dst)*100.0);
+           
     }
-#endif
+#endif      
     *SvEND(dst) = '\0';
     return dst;
 }