@@ -111,21 +111,11 @@ var CommentSpaceAllocator = (function () {
111111 }
112112 var pool = this . _pools [ cindex ] ;
113113 if ( pool . length === 0 ) {
114- pool . push ( comment ) ;
115114 comment . cindex = cindex ;
116115 return 0 ;
117116 } else if ( this . pathCheck ( 0 , comment , pool ) ) {
118117 // Has a path in the current pool
119118 comment . cindex = cindex ;
120- pool . binsert ( comment , function ( a , b ) {
121- if ( a . bottom < b . bottom ) {
122- return - 1 ;
123- } else if ( a . bottom === b . bottom ) {
124- return 0 ;
125- } else {
126- return 1 ;
127- }
128- } ) ;
129119 return 0 ;
130120 }
131121 var y = 0 ;
@@ -137,15 +127,6 @@ var CommentSpaceAllocator = (function () {
137127 if ( this . pathCheck ( y , comment , pool ) ) {
138128 // Has a path in the current pool
139129 comment . cindex = cindex ;
140- pool . binsert ( comment , function ( a , b ) {
141- if ( a . bottom < b . bottom ) {
142- return - 1 ;
143- } else if ( a . bottom === b . bottom ) {
144- return 0 ;
145- } else {
146- return 1 ;
147- }
148- } ) ;
149130 return y ;
150131 }
151132 }
@@ -166,6 +147,15 @@ var CommentSpaceAllocator = (function () {
166147 comment . y = 0 ;
167148 } else {
168149 comment . y = this . assign ( comment , 0 ) ;
150+ this . _pools [ comment . cindex ] . binsert ( comment , function ( a , b ) {
151+ if ( a . bottom < b . bottom ) {
152+ return - 1 ;
153+ } else if ( a . bottom > b . bottom ) {
154+ return 1 ;
155+ } else {
156+ return 0 ;
157+ }
158+ } ) ;
169159 }
170160 } ;
171161
@@ -178,6 +168,9 @@ var CommentSpaceAllocator = (function () {
178168 if ( comment . cindex < 0 ) {
179169 return ;
180170 }
171+ if ( comment . cindex >= this . _pools . length ) {
172+ throw new Error ( "cindex out of bounds" ) ;
173+ }
181174 var index = this . _pools [ comment . cindex ] . indexOf ( comment ) ;
182175 if ( index < 0 )
183176 return ;
0 commit comments