@@ -177,15 +177,19 @@ function sameColor(left: GhosttyColor, right: GhosttyColor): boolean {
177177}
178178
179179/** Bounds String.fromCodePoint arguments for cells with enormous combining-mark sequences. */
180- export function ghosttyCellText ( codepointView : DataView , graphemeLength : number ) : string {
181- if ( graphemeLength === 1 ) return String . fromCodePoint ( codepointView . getUint32 ( 0 , true ) ) ;
180+ export function ghosttyCellText (
181+ codepointView : DataView ,
182+ graphemeLength : number ,
183+ byteOffset = 0 ,
184+ ) : string {
185+ if ( graphemeLength === 1 ) return String . fromCodePoint ( codepointView . getUint32 ( byteOffset , true ) ) ;
182186 const CHUNK_SIZE = 4_096 ;
183187 let text = "" ;
184188 for ( let start = 0 ; start < graphemeLength ; start += CHUNK_SIZE ) {
185189 const count = Math . min ( CHUNK_SIZE , graphemeLength - start ) ;
186190 const codes = new Array < number > ( count ) ;
187191 for ( let index = 0 ; index < count ; index += 1 ) {
188- codes [ index ] = codepointView . getUint32 ( ( start + index ) * 4 , true ) ;
192+ codes [ index ] = codepointView . getUint32 ( byteOffset + ( start + index ) * 4 , true ) ;
189193 }
190194 text += String . fromCodePoint ( ...codes ) ;
191195 }
@@ -853,12 +857,12 @@ export class GhosttyTerminalCore {
853857 if ( rowDirty ) {
854858 this . rows [ rowIndex ] = this . readRow ( iterator , cols , foreground , background ) ;
855859 dirtyRows . add ( rowIndex ) ;
856- this . runtime . bytes ( this . scratch , 1 ) [ 0 ] = 0 ;
860+ this . runtime . memoryBytes ( ) [ this . scratch ] = 0 ;
857861 this . runtime . call ( "ghostty_render_state_row_set" , iterator , 0 , this . scratch ) ;
858862 }
859863 rowIndex += 1 ;
860864 }
861- this . runtime . view ( this . scratch , 4 ) . setUint32 ( 0 , 0 , true ) ;
865+ this . runtime . memoryDataView ( ) . setUint32 ( this . scratch , 0 , true ) ;
862866 this . runtime . call ( "ghostty_render_state_set" , this . renderState , 0 , this . scratch ) ;
863867 }
864868
@@ -1009,19 +1013,19 @@ export class GhosttyTerminalCore {
10091013 "ghostty_render_state_row_get(raw)" ,
10101014 this . runtime . call ( "ghostty_render_state_row_get" , iterator , ROW_DATA . raw , this . scratch ) ,
10111015 ) ;
1012- const rawRow = this . runtime . view ( this . scratch , 8 ) . getBigUint64 ( 0 , true ) ;
1013- this . runtime . bytes ( this . scratch + 8 , 1 ) [ 0 ] = 0 ;
1016+ const rawRow = this . runtime . memoryDataView ( ) . getBigUint64 ( this . scratch , true ) ;
1017+ this . runtime . memoryBytes ( ) [ this . scratch + 8 ] = 0 ;
10141018 this . assertSuccess (
10151019 "ghostty_row_get(wrap continuation)" ,
10161020 this . runtime . call ( "ghostty_row_get" , rawRow , 2 , this . scratch + 8 ) ,
10171021 ) ;
1018- const isWrapContinuation = this . runtime . bytes ( this . scratch + 8 , 1 ) [ 0 ] !== 0 ;
1019- this . runtime . bytes ( this . scratch + 8 , 1 ) [ 0 ] = 0 ;
1022+ const isWrapContinuation = this . runtime . memoryBytes ( ) [ this . scratch + 8 ] !== 0 ;
1023+ this . runtime . memoryBytes ( ) [ this . scratch + 8 ] = 0 ;
10201024 this . assertSuccess (
10211025 "ghostty_row_get(wrap)" ,
10221026 this . runtime . call ( "ghostty_row_get" , rawRow , 1 , this . scratch + 8 ) ,
10231027 ) ;
1024- const wrapsToNext = this . runtime . bytes ( this . scratch + 8 , 1 ) [ 0 ] !== 0 ;
1028+ const wrapsToNext = this . runtime . memoryBytes ( ) [ this . scratch + 8 ] !== 0 ;
10251029
10261030 this . assertSuccess (
10271031 "ghostty_render_state_row_get(cells)" ,
@@ -1034,15 +1038,13 @@ export class GhosttyTerminalCore {
10341038 ) ;
10351039 const cellsIterator = this . runtime . readPointer ( this . rowCellsSlot ) ;
10361040 const { size : styleSize , fields : styleFields } = this . runtime . layout ( "GhosttyStyle" ) ;
1041+ const cellsNext = this . runtime . fn ( "ghostty_render_state_row_cells_next" ) ;
1042+ const cellsGetMulti = this . runtime . fn ( "ghostty_render_state_row_cells_get_multi" ) ;
10371043 const cells : GhosttyCell [ ] = [ ] ;
1038- while (
1039- cells . length < cols &&
1040- this . runtime . call ( "ghostty_render_state_row_cells_next" , cellsIterator ) !== 0
1041- ) {
1042- this . runtime . bytes ( this . style , styleSize ) . fill ( 0 ) ;
1044+ while ( cells . length < cols && cellsNext ( cellsIterator ) !== 0 ) {
1045+ this . runtime . memoryBytes ( ) . fill ( 0 , this . style , this . style + styleSize ) ;
10431046 this . runtime . setField ( this . style , "GhosttyStyle" , "size" , styleSize ) ;
1044- const result = this . runtime . call (
1045- "ghostty_render_state_row_cells_get_multi" ,
1047+ const result = cellsGetMulti (
10461048 cellsIterator ,
10471049 5 ,
10481050 this . cellQuery + CELL_QUERY . keys ,
@@ -1081,8 +1083,7 @@ export class GhosttyTerminalCore {
10811083 ) === GHOSTTY_SUCCESS
10821084 ) {
10831085 // Byte allocations need not be 4-byte aligned; use DataView instead of Uint32Array.
1084- const codepointView = this . runtime . view ( this . graphemes , bufferSize ) ;
1085- text = ghosttyCellText ( codepointView , graphemeLength ) ;
1086+ text = ghosttyCellText ( this . runtime . memoryDataView ( ) , graphemeLength , this . graphemes ) ;
10861087 }
10871088 }
10881089 let wide = 0 ;
@@ -1097,13 +1098,13 @@ export class GhosttyTerminalCore {
10971098 this . scratch ,
10981099 ) ,
10991100 ) ;
1100- const rawCell = this . runtime . view ( this . scratch , 8 ) . getBigUint64 ( 0 , true ) ;
1101- this . runtime . view ( this . scratch + 8 , 4 ) . setUint32 ( 0 , 0 , true ) ;
1101+ const rawCell = this . runtime . memoryDataView ( ) . getBigUint64 ( this . scratch , true ) ;
1102+ this . runtime . memoryDataView ( ) . setUint32 ( this . scratch + 8 , 0 , true ) ;
11021103 this . assertSuccess (
11031104 "ghostty_cell_get(wide)" ,
11041105 this . runtime . call ( "ghostty_cell_get" , rawCell , RAW_CELL_DATA . wide , this . scratch + 8 ) ,
11051106 ) ;
1106- wide = this . runtime . view ( this . scratch + 8 , 4 ) . getUint32 ( 0 , true ) ;
1107+ wide = this . runtime . memoryDataView ( ) . getUint32 ( this . scratch + 8 , true ) ;
11071108 }
11081109 // Read the style after allocation and ABI calls, which can grow WASM memory.
11091110 const styleView = this . runtime . memoryDataView ( ) ;
@@ -1228,34 +1229,34 @@ export class GhosttyTerminalCore {
12281229 }
12291230
12301231 private getU16 ( data : number ) : number {
1231- this . runtime . bytes ( this . scratch , 2 ) . fill ( 0 ) ;
1232+ this . runtime . memoryDataView ( ) . setUint16 ( this . scratch , 0 , true ) ;
12321233 this . assertSuccess (
12331234 "ghostty_render_state_get" ,
12341235 this . runtime . call ( "ghostty_render_state_get" , this . renderState , data , this . scratch ) ,
12351236 ) ;
1236- return this . runtime . view ( this . scratch , 2 ) . getUint16 ( 0 , true ) ;
1237+ return this . runtime . memoryDataView ( ) . getUint16 ( this . scratch , true ) ;
12371238 }
12381239
12391240 private getU32 ( data : number ) : number {
1240- this . runtime . bytes ( this . scratch , 4 ) . fill ( 0 ) ;
1241+ this . runtime . memoryDataView ( ) . setUint32 ( this . scratch , 0 , true ) ;
12411242 this . assertSuccess (
12421243 "ghostty_render_state_get" ,
12431244 this . runtime . call ( "ghostty_render_state_get" , this . renderState , data , this . scratch ) ,
12441245 ) ;
1245- return this . runtime . view ( this . scratch , 4 ) . getUint32 ( 0 , true ) ;
1246+ return this . runtime . memoryDataView ( ) . getUint32 ( this . scratch , true ) ;
12461247 }
12471248
12481249 private getBool ( data : number ) : boolean {
1249- this . runtime . bytes ( this . scratch , 1 ) [ 0 ] = 0 ;
1250+ this . runtime . memoryBytes ( ) [ this . scratch ] = 0 ;
12501251 this . assertSuccess (
12511252 "ghostty_render_state_get" ,
12521253 this . runtime . call ( "ghostty_render_state_get" , this . renderState , data , this . scratch ) ,
12531254 ) ;
1254- return this . runtime . bytes ( this . scratch , 1 ) [ 0 ] !== 0 ;
1255+ return this . runtime . memoryBytes ( ) [ this . scratch ] !== 0 ;
12551256 }
12561257
12571258 private getColor ( data : number , fallback : GhosttyColor ) : GhosttyColor {
1258- this . runtime . bytes ( this . scratch , 3 ) . fill ( 0 ) ;
1259+ this . runtime . memoryBytes ( ) . fill ( 0 , this . scratch , this . scratch + 3 ) ;
12591260 const result = this . runtime . call (
12601261 "ghostty_render_state_get" ,
12611262 this . renderState ,
@@ -1266,15 +1267,15 @@ export class GhosttyTerminalCore {
12661267 }
12671268
12681269 private getRowBool ( iterator : number , data : number ) : boolean {
1269- this . runtime . bytes ( this . scratch , 1 ) [ 0 ] = 0 ;
1270+ this . runtime . memoryBytes ( ) [ this . scratch ] = 0 ;
12701271 return (
12711272 this . runtime . call ( "ghostty_render_state_row_get" , iterator , data , this . scratch ) ===
1272- GHOSTTY_SUCCESS && this . runtime . bytes ( this . scratch , 1 ) [ 0 ] !== 0
1273+ GHOSTTY_SUCCESS && this . runtime . memoryBytes ( ) [ this . scratch ] !== 0
12731274 ) ;
12741275 }
12751276
12761277 private getCellColor ( iterator : number , data : number , fallback : GhosttyColor ) : GhosttyColor {
1277- this . runtime . bytes ( this . scratch , 3 ) . fill ( 0 ) ;
1278+ this . runtime . memoryBytes ( ) . fill ( 0 , this . scratch , this . scratch + 3 ) ;
12781279 const result = this . runtime . call (
12791280 "ghostty_render_state_row_cells_get" ,
12801281 iterator ,
0 commit comments