about text editors
How to make a fast text editor?
First, let's think about where exactly it can
slow down editor?
The first bad thing is row insertion,
And a thought about this
If you simply shift all the lines after
inserted using Ldir (or something
something similar), then the insertion time will
children are proportional to the length of the text, This
bad, but for large texts - easy
terrible, You can avoid this by following
way,
Edited and entered line
put in the buffer, It's very fast,
You just have to write a program
which will be small pieces of re-
write the entire text in memory, T,e,, do-
let's say we have text from the address (conditional
but) Oh, 1 Okb long, And we have already managed to start
edit multiple lines and even
introduce new ones, Our program begins
rewrite text starting from zero
addresses, to addresses from 1Okb and beyond, When
this edited lines are not rewritten
are poured out, but taken from the buffer, Well,if
at this point we entered a new line, then
it is also inserted from the buffer, If
the line was deleted - skip, So
way, after we go all the way
old version of the text, from the address 1Okb we
we will get a new version in which there will be
all changes are reflected, 3 and this is the time,
maybe this new option will be in time too
become outdated, that is, new ones will appear in the buffer
(edited) versions of some
lines, Well, everything will happen again - our program
will continue to work, We believe that the memory
closed in a ring, here,
You just need all the other functions
place on im 2: cursor, output and re-
line editing, scroller and all that -
something, And at the same time let them borrow
as much time as they need, let
even several frames entirely, because
that the program that will deal
text update does not perform well
absolutely necessary, All text can be updated
pour even in a few minutes (although -
this is unlikely, most likely at most
- it will work for a few seconds)
The main thing is to choose the buffer size so that
while the text is being updated, it
I wouldn’t have time to overflow,
That's it, the speed of insertion depends on the size of the text.
ki no longer depends,
Well, these thoughts are probably not new, but -
exactly like that: a buffer for lines, not for
letters when polling the keyboard - in my opinion
no one onI didn’t do any speck, In any case,
tea, my goal is not to make discoveries - but,,,
uh, share experience, and personal one at that,
Here,
Okay, that's all good, but there is also
cons, Firstly, you need memory for a
fer, I think 1-2kb will be enough,
Secondly, it will be required for each line
to use up an extra three bytes, this is hell
res of the line (2) and its length (1), You will have to
organize a plate with this data and
when inserting/deleting rows, operate
with her, but the operations
move/copy/delete group
lines will simply be reactive, since
will be reduced to working with this sign, But -
the worst thing is that you have to limit
total number of lines in the text,
The addresses in the table will generally be
do not follow each other, some instructions -
They will point to the buffer. When deleted,
copying and copying strings in memory will
holes will form, But all these non-
It will be a pleasure to fix the update program
text,
Memory, of course, is a pity, But personally for
For me, performance comes first in the first month
those, Moreover, the texts are longer
I have never written more than 30 kb in my life,
Here, the first bad thing seems to have been bypassed
whether, There remains the second thing, absolutely
disgusting - text formatting,
Well, and, accordingly, a thought
The formatting algorithm I present
as follows, We take a word from informal
matted text, Let's see, it fits
does it fit into the current line? If it fits,
take the following, If it doesn’t fit, we torture-
to bear it, Here, no matter how you come up with it,
shaft, I got two passes along
word:
1) Hyphenation in a word,
T,e,, in fact, marking letters on the
a word can be cut off;
2) View a word by syllables, Similar to
but to the words: fits into the line - we print,
doesn’t fit - close the current line and
starting a new one,
Here is what is written in paragraph 1
performed at the stage of inserting a line into the book
fer, For one line this is according to any bu-
children take a little time, but in the end,
when formatting, for all text it is
will give a significant gain in speed,
In addition, whenmore formatting for us
must be highlighted in the line itself
words are not so simple either, and this
can be done when inserting a line into a buffer
(when you press enter, i.e.),
In general, half of the entire work of the format
can be done unnoticed in the process
text editing, And this is necessary
use,
Well, again, this will have an impact (slightly)
specifically) on memory consumption,
How can this be done specifically, All
Let's group the text by words, To each
we will assign attributes (1-2 bytes) to the word, in
which we will write down the number of spaces
edit word, word length, controlling co-
dy before the word and the presence of managers
codes in the word itself, the latter, of course,
not important, but also gives a win
in speed - can be considered separately
say words that contain control,
codes and words in which they are not present
exist, they are not present in 99% of words,
i.e. color, font, etc., changes between
words, and not in them, Here,
Well, let’s also make our font consisting of
of 128 characters, not 256, Switch-
you will have to differentiate between Russian/Latin fonts
issue manager codes, But 7th
the letter bit can be used for marking
admissibility of setting a transfer after
of this letter,
That's it,
Cons:encoding/decoding
(i.e. slowdown) when writing/reading
ordinary texts,
That's all I wanted to say in
water of text editors,
One of my unfinished projects
this is exactly what the editor is, I was able to
implement everything, it seems, from the above-
numerical, but did not actually write
text formatting, Well, for some reason
work has slowed down and is now moving forward
extremely sluggishly, However, some
I'll probably release the aLfa version by winter,
Here,
Share your thoughts about the article