@@ -49,11 +49,11 @@ import {
4949import { flatToTree } from './flatToTree'
5050import palettes from './ggplotPalettes'
5151import { measureTextCanvas } from './measureTextCanvas'
52- import { calculateNeighborJoiningTree } from './neighborJoining'
5352import { DataModelF } from './model/DataModel'
5453import { DialogQueueSessionMixin } from './model/DialogQueue'
5554import { MSAModelF } from './model/msaModel'
5655import { TreeModelF } from './model/treeModel'
56+ import { calculateNeighborJoiningTree } from './neighborJoining'
5757import { parseAsn1 } from './parseAsn1'
5858import parseNewick from './parseNewick'
5959import A3mMSA from './parsers/A3mMSA'
@@ -847,8 +847,10 @@ function stateModelFactory() {
847847 * Returns a map of row name to array of insertions with display position and letters
848848 */
849849 get insertionPositions ( ) {
850+ const { hideGapsEffective } = self
850851 const { blanks, rows } = this
851- if ( blanks . length === 0 ) {
852+ const blanksLen = blanks . length
853+ if ( blanksLen === 0 || ! hideGapsEffective ) {
852854 return new Map < string , { pos : number ; letters : string } [ ] > ( )
853855 }
854856 const result = new Map < string , { pos : number ; letters : string } [ ] > ( )
@@ -857,28 +859,36 @@ function stateModelFactory() {
857859 let displayPos = 0
858860 let blankIdx = 0
859861 let currentInsertPos = - 1
860- let currentLetters = ''
861- for ( let i = 0 ; i < seq . length ; i ++ ) {
862- if ( blankIdx < blanks . length && blanks [ blankIdx ] === i ) {
863- const char = seq [ i ] !
864- if ( char !== '-' && char !== '.' ) {
862+ let letterChars : string [ ] = [ ]
863+ const seqLen = seq . length
864+ for ( let i = 0 ; i < seqLen ; i ++ ) {
865+ if ( blankIdx < blanksLen && blanks [ blankIdx ] === i ) {
866+ // bit trick: (code - 45) >>> 0 <= 1 checks for '-' (45) or '.' (46)
867+ const code = seq . charCodeAt ( i )
868+ if ( ! ( ( code - 45 ) >>> 0 <= 1 ) ) {
865869 if ( currentInsertPos === displayPos ) {
866- currentLetters += char
870+ letterChars . push ( seq [ i ] ! )
867871 } else {
868- if ( currentLetters ) {
869- insertions . push ( { pos : currentInsertPos , letters : currentLetters } )
872+ if ( letterChars . length > 0 ) {
873+ insertions . push ( {
874+ pos : currentInsertPos ,
875+ letters : letterChars . join ( '' ) ,
876+ } )
870877 }
871878 currentInsertPos = displayPos
872- currentLetters = char
879+ letterChars = [ seq [ i ] ! ]
873880 }
874881 }
875882 blankIdx ++
876883 } else {
877884 displayPos ++
878885 }
879886 }
880- if ( currentLetters ) {
881- insertions . push ( { pos : currentInsertPos , letters : currentLetters } )
887+ if ( letterChars . length > 0 ) {
888+ insertions . push ( {
889+ pos : currentInsertPos ,
890+ letters : letterChars . join ( '' ) ,
891+ } )
882892 }
883893 if ( insertions . length > 0 ) {
884894 result . set ( name , insertions )
0 commit comments