Re: Bug in ed

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hi, Daniel:

I wrote my editor on my 386sx, and attempted to optimize it for that
environment. It will run fairly quickly. However, there *are* some things
that slow it down:

1. Graphics mode. You should ONLY run the editor in text mode!
2. Syntax coloring. Turn it off for a signifigant speed increase.
3. Selecting regions.

The code in XLE.E handles Single Line Edits (SLEs) and Multiple Line Edits
(MLEs). The editor is basically one big MLE. Of all the controls, the MLE
is the most graphic intensive ('cos it writes multiple lines, duh). But it
*is* optimized for speed.

After handling an edit key, the following items are checked for changes:

   - leftmost column has changed (full screen scrolled left or right)
   - top line has changed (page has scrolled)
   - local redraw flag has been set (internal to function)
   - global redraw flag has been set (set by user)

In the case of any of these being true, the full screen will be redrawn.
The local redraw flag is typically triggered by an area being
selected/deselected. The logic with selected regions gets complex, and
often I'll just bail and refresh the whole screen. Even then, there are
some cases where you get this "leftover" selected text garbage on your
screen.

But most of the time, only the current line gets redrawn. For example,
moving the cursor one line at a time will *not* cause anything but the
current lines to be refreshed.

Scrolling up and down a single line is also optimized, with the routines
move_up() and move_down():

------------------------------------------------------------------------
-----
function move_down( sequence mle )

   -- move down by one line

   if mle[ITEM] < mle[DEEP] then
      -- is there a line to scroll to?
      if current_line( mle ) < length( mle[ITEMS] ) then
         -- move to next line
         mle[ITEM] = mle[ITEM] + 1

         -- draw the line we moved from
         draw_mle_item( mle, mle[ITEM] - 1 )

      end if
   else
      -- can we scroll?
      if mle[TOP_LINE]+mle[DEEP]-1 < length( mle[ITEMS] ) then
         if VGA_MODE then
            -- force redraw
            mle[TOP_LINE] = mle[TOP_LINE] + 1
         else
             -- physical scroll
             mle_scroll( mle, -1 )

             -- adjust settings
             mle[TOP_LINE] = mle[TOP_LINE] + 1

             -- draw the line we moved from
             draw_mle_item( mle, mle[ITEM] - 1 )

             -- prevent redraw of screen
             oldFirstLine = mle[TOP_LINE]

         end if

      end if
   end if

   -- return mle
   return mle

end function
------------------------------------------------------------------------
-----

If the VGA-mode flag is not set (read: in text mode), the routine
mle_scroll() is used to draw the screen. mle_scroll() uses
save_clean_image() and display_clean_image(), which are defined in
TEXTMODE.E. These are low-level calls that turn the mouse off and on before
doing their work - somthing not needed anymore, now that I've seperated the
VGA and SVGA code into seperate modules.

As a side note, I initially tried using the Euphoria function scroll(), but
the way it handles the left- and right-most columns is funky (and
undocumented. mild grrrrr...).

You may have noticed that it's also slower than ed in loading files. That's
because it converts tabs into spaces, and strips off the line feed at the
end of the line.

So:

1. The editor code is optimized, but I'm sure it could be done better.
2. There is a built in scroll() routine in Euphoria, but you probably are
better off using save_text_image() and display_text_image() instead.

Hope this answered your questions!

-- David

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu