Skip to content

Commit 0d4fe31

Browse files
committed
In ast_to_js.js, store scopes.lines to avoid computing it each time get_source_from_position() is called
1 parent d34a9e9 commit 0d4fe31

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

www/src/ast_to_js.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ $B.decode_position = function(pos){
144144
return pos
145145
}
146146

147-
function get_source_from_position(src, ast_obj){
148-
var lines = src.split('\n'),
147+
function get_source_from_position(scopes, ast_obj){
148+
scopes.lines = scopes.lines ?? scopes.src.split('\n')
149+
var lines = scopes.lines,
149150
start_line = lines[ast_obj.lineno - 1],
150151
res
151152
if(ast_obj.end_lineno == ast_obj.lineno){
@@ -1056,7 +1057,7 @@ $B.ast.Assert.prototype.to_js = function(scopes){
10561057
}
10571058

10581059
function annotation_to_str(obj, scopes){
1059-
return get_source_from_position(scopes.src, obj)
1060+
return get_source_from_position(scopes, obj)
10601061
}
10611062

10621063
$B.ast.AnnAssign.prototype.to_js = function(scopes){
@@ -4288,7 +4289,7 @@ $B.js_from_root = function(arg){
42884289
src = arg.src,
42894290
namespaces = arg.namespaces,
42904291
imported = arg.imported
4291-
4292+
42924293
if($B.show_ast_dump){
42934294
console.log($B.ast_dump(ast_root))
42944295
}

www/src/brython.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ $B.unicode_bidi_whitespace=[9,10,11,12,13,28,29,30,31,32,133,5760,8192,8193,8194
209209
;
210210
__BRYTHON__.implementation=[3,13,1,'dev',0]
211211
__BRYTHON__.version_info=[3,13,0,'final',0]
212-
__BRYTHON__.compiled_date="2024-11-05 08:16:06.546261"
213-
__BRYTHON__.timestamp=1730790966546
212+
__BRYTHON__.compiled_date="2024-11-05 10:25:30.265416"
213+
__BRYTHON__.timestamp=1730798730264
214214
__BRYTHON__.builtin_module_names=["_ajax","_ast","_base64","_binascii","_io_classes","_json","_jsre","_locale","_multiprocessing","_posixsubprocess","_profile","_random","_sre","_sre_utils","_string","_strptime","_svg","_symtable","_tokenize","_webcomponent","_webworker","_zlib_utils","_zlib_utils1","_zlib_utils_kozh","array","builtins","dis","encoding_cp932","encoding_cp932_v2","hashlib","html_parser","marshal","math","modulefinder","posix","pyexpat","python_re","python_re_new","unicodedata","xml_helpers","xml_parser","xml_parser_backup"]
215215
;
216216

@@ -11424,7 +11424,8 @@ target.end_lineno=origin.end_lineno
1142411424
target.end_col_offset=origin.end_col_offset}
1142511425
function encode_position(a,b,c,d){if(d===undefined){return `[${[a, b, c]}]`}else{return `[${[a, b, c, d]}]`}}
1142611426
$B.decode_position=function(pos){return pos}
11427-
function get_source_from_position(src,ast_obj){var lines=src.split('\n'),start_line=lines[ast_obj.lineno-1],res
11427+
function get_source_from_position(scopes,ast_obj){scopes.lines=scopes.lines ?? scopes.src.split('\n')
11428+
var lines=scopes.lines,start_line=lines[ast_obj.lineno-1],res
1142811429
if(ast_obj.end_lineno==ast_obj.lineno){res=start_line.substring(ast_obj.col_offset,ast_obj.end_col_offset)}else{var res=start_line.substr(ast_obj.col_offset),line_num=ast_obj.lineno+1
1142911430
while(line_num < ast_obj.end_lineno){res+=lines[line_num-1].trimLeft()
1143011431
line_num++}
@@ -11748,7 +11749,7 @@ return}else if(last.type=="def"){ix=scopes.indexOf(last)-1}else{return}}}}
1174811749
$B.ast.Assert.prototype.to_js=function(scopes){var test=$B.js_from_ast(this.test,scopes),msg=this.msg ? $B.js_from_ast(this.msg,scopes):"''",position=encode_position(this.test.col_offset,this.test.col_offset,this.test.end_col_offset)
1174911750
var js=`$B.set_lineno(frame, ${this.lineno})\n`
1175011751
return js+`$B.assert(${test}, ${msg}, ${position})`}
11751-
function annotation_to_str(obj,scopes){return get_source_from_position(scopes.src,obj)}
11752+
function annotation_to_str(obj,scopes){return get_source_from_position(scopes,obj)}
1175211753
$B.ast.AnnAssign.prototype.to_js=function(scopes){compiler_check(this)
1175311754
var postpone_annotation=scopes.symtable.table.future.features &
1175411755
$B.CO_FUTURE_ANNOTATIONS

www/src/version_info.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__BRYTHON__.implementation = [3, 13, 1, 'dev', 0]
22
__BRYTHON__.version_info = [3, 13, 0, 'final', 0]
3-
__BRYTHON__.compiled_date = "2024-11-05 08:16:06.546261"
4-
__BRYTHON__.timestamp = 1730790966546
3+
__BRYTHON__.compiled_date = "2024-11-05 10:25:30.265416"
4+
__BRYTHON__.timestamp = 1730798730264
55
__BRYTHON__.builtin_module_names = ["_ajax",
66
"_ast",
77
"_base64",

0 commit comments

Comments
 (0)