@@ -145,52 +145,46 @@ function constructTree(
145145 // Insert language from proxy with its parents
146146 // to local tree since common point or from the top
147147 function f ( lang ) {
148+ languageMap . intersection . add ( compositeIdToString ( lang . id ) ) ;
148149 let parents = [ lang . id ] ;
149- let cur_lang = lang ;
150150 let parent_id = lang . parent_id ;
151- let common_point = false ;
151+ let parent_id_str = compositeIdToString ( parent_id ) ;
152+ let common_point = languageMap . intersection . has ( parent_id_str ) && parent_id_str ;
152153
153- while ( parent_id !== null && ! common_point ) {
154+ while ( parent_id && ! common_point ) {
155+ languageMap . intersection . add ( parent_id_str ) ;
154156 parents = [ parent_id , [ parents ] ] ;
155- parent_id = compositeIdToString ( parent_id ) ;
156- common_point = languageMap . intersection . has ( parent_id ) ;
157- cur_lang = languageMap . proxy [ parent_id ] ;
158- parent_id = cur_lang . parent_id ;
157+ parent_id = languageMap . proxy [ parent_id_str ] . parent_id ;
158+ parent_id_str = compositeIdToString ( parent_id ) ;
159+ common_point = languageMap . intersection . has ( parent_id_str ) && parent_id_str ;
159160 }
160161
161162 let stub = tree [ 1 ] ;
162163
163- if ( parents . length > 1 ) {
164- const proxy_id = compositeIdToString ( parents [ 0 ] ) ;
165- parents = parents [ 1 ] ;
166-
167- // Getting stub of tree to place subtree from proxy since top of this stub
168- function g ( stb ) {
169- for ( const s of stb ) {
170- const local_id = compositeIdToString ( s [ 0 ] ) ;
164+ function g ( stb ) {
165+ if ( ! common_point ) {
166+ return ;
167+ }
171168
172- if ( local_id === proxy_id ) {
173- if ( s . length === 1 ) {
174- s [ s . length ] = [ ] ;
175- }
176- stub = s [ 1 ] ;
177- break ;
169+ for ( const s of stb ) {
170+ const local_id = compositeIdToString ( s [ 0 ] ) ;
178171
179- } else if ( s . length > 1 ) {
180- g ( s [ 1 ] ) ;
172+ if ( local_id === common_point ) {
173+ if ( s . length === 1 ) {
174+ s [ s . length ] = [ ] ;
181175 }
182- }
183- }
176+ stub = s [ 1 ] ;
177+ break ;
184178
185- // Getting stub of tree only if common_point exists
186- // otherwise the function returns full tree so this makes no sense
187- if ( common_point ) {
188- g ( stub ) ;
179+ } else if ( s . length > 1 ) {
180+ g ( s [ 1 ] ) ;
181+ }
189182 }
190183 }
191184
192- // Add languages from proxy at beginning of branch
193- stub . unshift ( ...parents ) ;
185+ // Cutting off tree and add languages from proxy at beginning of branch
186+ g ( stub ) ;
187+ stub . unshift ( parents ) ;
194188 }
195189
196190 // Iterate through language_union (local+proxy)
0 commit comments