@@ -61,35 +61,33 @@ define(["text!bcompile.js", "bytecode-table"], function make_bcompile(bcompile_s
61
61
scope : 0 ,
62
62
desugar_frame_get : ! dont_desugar_frame_get
63
63
} ;
64
- // literal symbol table. Does string intern'ing too. Very simple.
64
+ // literal symbol table. Does string intern'ing too.
65
+ var ObjectIs = Object . is || function ( a , b ) {
66
+ if ( typeof ( a ) === 'number' && typeof ( b ) === 'number' ) {
67
+ if ( a !== a ) { return ( b !== b ) ; } // NaN
68
+ if ( a === 0 ) { return ( b === 0 ) && ( 1 / a === 1 / b ) ; } // +/- 0
69
+ }
70
+ return ( a === b ) ;
71
+ } ;
72
+ var literalMap = Object . create ( null ) ;
65
73
state . literal = function ( val ) {
66
- var i = 0 , l ;
67
- if ( Object . is ) {
68
- while ( i < this . literals . length ) {
69
- l = this . literals [ i ] ;
70
- if ( Object . is ( l , val ) ) { return i ; }
71
- i += 1 ;
72
- }
73
- } else if ( ! ( val === val ) ) { // Look for NaN
74
- while ( i < this . literals . length ) {
75
- l = this . literals [ i ] ;
76
- if ( ! ( l === l ) ) { return i ; }
77
- i += 1 ;
78
- }
79
- } else if ( val === 0 ) { // Handle +/-0
80
- while ( i < this . literals . length ) {
81
- l = this . literals [ i ] ;
82
- if ( l === 0 && ( 1 / l ) === ( 1 / val ) ) { return i ; }
83
- i += 1 ;
84
- }
85
- } else { // Everything else
86
- while ( i < this . literals . length ) {
87
- l = this . literals [ i ] ;
88
- if ( l === val ) { return i ; }
74
+ var i , pair , key , entries ;
75
+ key = typeof ( val ) + ':' + val ; // very basic hash key
76
+ entries = literalMap [ key ] ;
77
+ if ( entries !== undefined ) {
78
+ i = 0 ;
79
+ while ( i < entries . length ) {
80
+ pair = entries [ i ] ;
81
+ if ( ObjectIs ( pair [ 0 ] , val ) ) { return pair [ 1 ] ; }
89
82
i += 1 ;
90
83
}
84
+ } else {
85
+ entries = [ ] ;
86
+ literalMap [ key ] = entries ;
91
87
}
88
+ i = this . literals . length ;
92
89
this . literals [ i ] = val ;
90
+ entries . push ( [ val , i ] ) ;
93
91
return i ;
94
92
} ;
95
93
// create a function representation
0 commit comments