cedric pushed a commit to branch master.

http://git.enlightenment.org/apps/terminology.git/commit/?id=964e1f39a972052ce54f1d4fc0e01aad40aa6d44

commit 964e1f39a972052ce54f1d4fc0e01aad40aa6d44
Author: Cedric Bail <[email protected]>
Date:   Mon Oct 28 18:55:53 2013 +0900

    terminology: factorise some code and help the compiler figure out which 
branch is the most likely one.
---
 src/bin/termptyops.c | 38 +++++++++++++-------------------------
 1 file changed, 13 insertions(+), 25 deletions(-)

diff --git a/src/bin/termptyops.c b/src/bin/termptyops.c
index 2547038..91bb781 100644
--- a/src/bin/termptyops.c
+++ b/src/bin/termptyops.c
@@ -204,7 +204,7 @@ _termpty_text_append(Termpty *ty, const Eina_Unicode 
*codepoints, int len)
                                         &(cells[ty->state.cx]), 1);
 #if defined(SUPPORT_DBLWIDTH)
         cells[ty->state.cx].att.dblwidth = _termpty_is_dblwidth_get(ty, g);
-        if ((cells[ty->state.cx].att.dblwidth) && (ty->state.cx < (ty->w - 1)))
+        if (EINA_UNLIKELY((cells[ty->state.cx].att.dblwidth) && (ty->state.cx 
< (ty->w - 1))))
           {
              TERMPTY_FMTCLR(cells[ty->state.cx].att);
              termpty_cell_codepoint_att_fill(ty, 0, cells[ty->state.cx].att,
@@ -213,44 +213,32 @@ _termpty_text_append(Termpty *ty, const Eina_Unicode 
*codepoints, int len)
 #endif        
         if (ty->state.wrap)
           {
+             unsigned char offset = 1;
+
              ty->state.wrapnext = 0;
 #if defined(SUPPORT_DBLWIDTH)
-             if (cells[ty->state.cx].att.dblwidth)
-               {
-                  if (ty->state.cx >= (ty->w - 2)) ty->state.wrapnext = 1;
-                  else ty->state.cx += 2;
-               }
-             else
-               {
-                  if (ty->state.cx >= (ty->w - 1)) ty->state.wrapnext = 1;
-                  else ty->state.cx++;
-               }
-#else
-             if (ty->state.cx >= (ty->w - 1)) ty->state.wrapnext = 1;
-             else ty->state.cx++;
+            if (EINA_UNLIKELY(cells[ty->state.cx].att.dblwidth))
+               offset = 2;
 #endif
+             if (EINA_UNLIKELY(ty->state.cx >= (ty->w - offset))) 
ty->state.wrapnext = 1;
+             else ty->state.cx += offset;
           }
         else
           {
+             unsigned char offset = 1;
+
              ty->state.wrapnext = 0;
              ty->state.cx++;
              if (ty->state.cx >= (ty->w - 1)) return;
 #if defined(SUPPORT_DBLWIDTH)
-             if (cells[ty->state.cx].att.dblwidth)
+             if (EINA_UNLIKELY(cells[ty->state.cx].att.dblwidth))
                {
                   ty->state.cx++;
-                  if (ty->state.cx >= (ty->w - 1))
-                    ty->state.cx = ty->w - 2;
-               }
-             else
-               {
-                  if (ty->state.cx >= ty->w)
-                    ty->state.cx = ty->w - 1;
+                  offset = 2;
                }
-#else
-             if (ty->state.cx >= ty->w)
-               ty->state.cx = ty->w - 1;
 #endif
+             if (ty->state.cx >= (ty->w - (offset - 1)))
+               ty->state.cx = ty->w - offset;
           }
      }
 }

-- 


Reply via email to