Skip to content

Commit 2a09a90

Browse files
committed
优化js运行效率
1 parent 1f94e6a commit 2a09a90

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

Lexical/index.html

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -132,38 +132,31 @@ <h3 class="ui header">Lexical analyer output</h4>
132132
$('#out').html('');
133133
$('#token').html('');
134134
}
135+
var token = '';
136+
var out = '';
135137
data.forEach(function(entry){
136-
if(first == 0) {
137-
$('#token').html('<a class="tiny ui basic circular label">#' + entry['pos'][0] + '</a>');
138-
$('#token').append('<a class="tiny ui ' + color[entry['tuple'][0]] + ' label" data-title="Token Info" data-content="'+
139-
"Type: " + entry['type'] + ", Pointer: " + entry['tuple'][1] + ", Postion: (" + entry['pos'][0] + ', ' + entry['pos'][1] + ')'
140-
+'">' + entry['word'] + '</a>');
141-
$('#out').html("<tr class='"+ (entry["type"] == "ERROR"?"negative":"") +"'><td>"+first+"</td><td>"+entry["word"]+
142-
"</td><td>("+entry["tuple"][0]+", "+entry["tuple"][1]+")</td><td>"+
143-
entry["type"] + "</td><td>(" + entry["pos"][0] + ", " + entry["pos"][1] + ")</td></tr>"
144-
);
145-
}
146-
else {
147-
if(lastrow != entry['pos'][0])
148-
$('#token').append('<hr><a class="tiny ui basic circular label">#' + entry['pos'][0] + '</a>');
138+
if(lastrow != entry['pos'][0])
139+
token += '<hr><a class="tiny ui basic circular label">#' + entry['pos'][0] + '</a>';
140+
token +='<a class="tiny ui ' + color[entry['tuple'][0]] + ' label" data-title="Token Info" data-content="'+
141+
"Type: " + entry['type'] + ", Pointer: " + entry['tuple'][1] + ", Postion: (" + entry['pos'][0] + ', ' + entry['pos'][1] + ')'
142+
+'">' + entry['word'] + '</a>';
143+
out += "<tr class='"+ (entry["type"] == "ERROR"?"negative":"") +"'><td>"+first+"</td><td>"+entry["word"]+
144+
"</td><td>("+entry["tuple"][0]+", "+entry["tuple"][1]+")</td><td>"+
145+
entry["type"] + "</td><td>(" + entry["pos"][0] + ", " + entry["pos"][1] + ")</td></tr>";
149146

150-
$('#token').append('<a class="tiny ui ' + color[entry['tuple'][0]] + ' label" data-title="Token Info" data-content="'+
151-
"Type: " + entry['type'] + ", Pointer: " + entry['tuple'][1] + ", Postion: (" + entry['pos'][0] + ', ' + entry['pos'][1] + ')'
152-
+'">' + entry['word'] + '</a>');
153-
$('#out').append("<tr class='"+ (entry["type"] == "ERROR"?"negative":"") +"'><td>"+first+"</td><td>"+entry["word"]+
154-
"</td><td>("+entry["tuple"][0]+", "+entry["tuple"][1]+")</td><td>"+
155-
entry["type"] + "</td><td>(" + entry["pos"][0] + ", " + entry["pos"][1] + ")</td></tr>"
156-
);
157-
}
158147
++first;
159148
lastrow = entry['pos'][0];
160-
$('#token a').popup();
161149
});
150+
// console.log(token);
151+
// console.log(out);
152+
$('#token').html(token);
153+
$('#out').html(out);
154+
$('#token a').popup();
162155
}
163156
});
164157
}
165158

166-
$('textarea').on('change keyup paste', update);
159+
$('textarea').on('keyup paste', update);
167160

168161
$('textarea').val(
169162
"int a = 2, b = 3;\n" +

0 commit comments

Comments
 (0)