Skip to content
Snippets Groups Projects
Commit 502bc31e authored by deuce's avatar deuce
Browse files

Get rid of regexps in make_lines(). Use str.charAt() rather than

str.substr(0,1) use offsets rather than reassigning the string.

Probobly about half the time to do this... still too damn long though... should
probobly attempt to merge the attr generation too.
parent 8aef7fea
Branches
Tags
No related merge requests found
...@@ -707,6 +707,8 @@ function make_lines(str, attr, nl_is_hardcr) ...@@ -707,6 +707,8 @@ function make_lines(str, attr, nl_is_hardcr)
nl=new Array(); nl=new Array();
var oldstr=str; var oldstr=str;
var oldattr=attr; var oldattr=attr;
var spos=0;
var apos=0;
thisattr=7; thisattr=7;
/* Fix up the attr string to match str in length... /* Fix up the attr string to match str in length...
...@@ -714,18 +716,17 @@ function make_lines(str, attr, nl_is_hardcr) ...@@ -714,18 +716,17 @@ function make_lines(str, attr, nl_is_hardcr)
*/ */
str=''; str='';
attr=''; attr='';
while(oldstr.length) { while(spos < oldstr.length) {
if(oldattr.length) { if(apos < oldattr.length) {
thisattr=ascii(oldattr.substr(0,1)); thisattr=ascii(oldattr.charAt(apos));
oldattr=oldattr.substr(1); apos++;
} }
switch(oldstr.substr(0,1)) { switch(oldstr.charAt(spos)) {
case '\r': case '\r':
oldstr=oldstr.substr(1);
break; break;
case '\x01': case '\x01':
oldstr=oldstr.substr(1); spos++;
switch(oldstr.substr(0,1).toUpperCase()) { switch(oldstr.charAt(spos).toUpperCase()) {
case 'K': case 'K':
thisattr&=0xf8; thisattr&=0xf8;
break; break;
...@@ -784,28 +785,27 @@ function make_lines(str, attr, nl_is_hardcr) ...@@ -784,28 +785,27 @@ function make_lines(str, attr, nl_is_hardcr)
thisattr=7; thisattr=7;
break; break;
case '\x01': case '\x01':
str=str+'\x01'; str+='\x01';
attr=attr+ascii(thisattr); attr+=ascii(thisattr);
break; break;
default: default:
} }
oldstr=oldstr.substr(1);
break; break;
default: default:
str=str+oldstr.substr(0,1); str+=oldstr.charAt(spos);
oldstr=oldstr.substr(1);
attr=attr+ascii(thisattr); attr=attr+ascii(thisattr);
} }
spos++;
} }
while(str.length>0) { spos=0;
while(spos < str.length) {
var done=false; var done=false;
nl[nl.length]=new Line; nl[nl.length]=new Line;
while(str.length>0 && !done) { while(spos < str.length && !done) {
switch(str.substr(0,1)) { switch(str.charAt(spos)) {
case '\n': case '\n':
str=str.substr(1); spos++;
attr=attr.substr(1);
done=true; done=true;
if(nl_is_hardcr) if(nl_is_hardcr)
nl[nl.length-1].hardcr=true; nl[nl.length-1].hardcr=true;
...@@ -815,11 +815,11 @@ function make_lines(str, attr, nl_is_hardcr) ...@@ -815,11 +815,11 @@ function make_lines(str, attr, nl_is_hardcr)
/* If there is room for the first word of the next line on this /* If there is room for the first word of the next line on this
* line, it is hard */ * line, it is hard */
/* Otherwise, it is soft. */ /* Otherwise, it is soft. */
if(str.substr(0,1)==' ' || str.substr(0,1)=='\t') if(str.charAt(spos)==' ' || str.charAt(spos)=='\t')
nl[nl.length-1].hardcr=true; nl[nl.length-1].hardcr=true;
else { else {
var len; var len;
for(len=0; str.length>=len && str.substr(len,1)!=' ' && str.substr(len,1)!='\t'; len++); for(len=0; str.length>=len+spos && str.charAt(spos+len)!=' ' && str.charAt(spos+len,1)!='\t'; len++);
if(nl[nl.length-1].text.length+len < 80) if(nl[nl.length-1].text.length+len < 80)
nl[nl.length-1].hardcr=true; nl[nl.length-1].hardcr=true;
} }
...@@ -827,36 +827,32 @@ function make_lines(str, attr, nl_is_hardcr) ...@@ -827,36 +827,32 @@ function make_lines(str, attr, nl_is_hardcr)
break; break;
case ' ': /* Whitespace... never wrap here. */ case ' ': /* Whitespace... never wrap here. */
case '\t': case '\t':
nl[nl.length-1].text+=str.substr(0,1); nl[nl.length-1].text+=str.charAt(spos);
nl[nl.length-1].attr+=attr.substr(0,1); nl[nl.length-1].attr+=attr.charAt(spos);
str=str.substr(1); spos++;
attr=attr.substr(1);
break; break;
default: /* Printable char... may need to wrap */ default: /* Printable char... may need to wrap */
if(nl[nl.length-1].text.length>79) { /* Need to have wrapped */ if(nl[nl.length-1].text.length>79) { /* Need to have wrapped */
var offset; var offset;
for(offset=nl[nl.length-1].text.length-1; offset>=0; offset--) { for(offset=nl[nl.length-1].text.length-1; offset>=0; offset--) {
if(nl[nl.length-1].text.substr(offset,1)!=' ' && nl[nl.length-1].text.substr(offset,1)!='\t') { if(nl[nl.length-1].text.charAt(offset)!=' ' && nl[nl.length-1].text.charAt(offset)!='\t') {
str=nl[nl.length-1].text.substr(offset)+str; /* ToDo: Verify/test this... it's probobly wrong */
attr=nl[nl.length-1].attr.substr(offset)+attr; spos-=nl[nl.length-1].text.length-1-offset;
spos--;
break; break;
} }
} }
if(offset==-1) { if(offset==-1) {
/* There were no spaces this line. */ /* There were no spaces this line. */
nl[nl.length-1].text=str.substr(0,79);
nl[nl.length-1].attr=attr.substr(0,79);
nl[nl.length-1].kludged=true; nl[nl.length-1].kludged=true;
str=str.substr(79); spos--;
attr=attr.substr(79);
} }
done=true; done=true;
} }
else { else {
nl[nl.length-1].text+=str.substr(0,1); nl[nl.length-1].text+=str.charAt(spos);
nl[nl.length-1].attr+=attr.substr(0,1); nl[nl.length-1].attr+=attr.charAt(spos);
str=str.substr(1); spos++;
attr=attr.substr(1);
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment