@@ -286,6 +286,40 @@ private StringVectorDataPtr(RStringVector vector) {
286286 protected Object getNativeTypeImpl (RFFIContext rffi ) {
287287 return rffi .getSulongArrayType (42L );
288288 }
289+
290+ @ ExportMessage
291+ public Object readArrayElement (long index ,
292+ @ Cached FFIToNativeMirrorNode wrapperNode ,
293+ @ CachedLibrary (limit = "DATA_LIB_LIMIT" ) VectorDataLibrary dataLib ) {
294+ String result = dataLib .getStringAt (vectorData , (int ) index );
295+ Object wrappedInCharSXP = CharSXPWrapper .create (result );
296+ return wrapperNode .execute (wrappedInCharSXP );
297+ }
298+
299+ @ ExportMessage
300+ protected void writeArrayElement (long index , Object value ,
301+ @ Cached FFIUnwrapNode unwrapNode ,
302+ @ Cached FFIUnwrapString unwrapString ,
303+ @ Cached ("createBinaryProfile()" ) ConditionProfile isWrappedProfile ,
304+ @ Cached ("createBinaryProfile()" ) ConditionProfile isStringWrappedProfile ,
305+ @ Cached BranchProfile notMaterializedBranchProfile ,
306+ @ CachedLibrary (limit = "DATA_LIB_LIMIT" ) VectorDataLibrary dataLib ,
307+ @ CachedLibrary (limit = "DATA_LIB_LIMIT" ) AbstractContainerLibrary containerLib ) {
308+ Object unwrappedValue = value ;
309+ if (isWrappedProfile .profile (value instanceof NativeDataAccess .NativeMirror )) {
310+ unwrappedValue = unwrapNode .execute (value );
311+ }
312+ if (isStringWrappedProfile .profile (unwrappedValue instanceof CharSXPWrapper )) {
313+ unwrappedValue = unwrapString .execute (unwrappedValue );
314+ }
315+ if (!dataLib .isWriteable (vectorData )) {
316+ notMaterializedBranchProfile .enter ();
317+ containerLib .materializeData (vector );
318+ vectorData = vector .getData ();
319+ assert dataLib .isWriteable (vectorData );
320+ }
321+ dataLib .setElementAt (vectorData , RRuntime .interopArrayIndexToInt (index , vector ), unwrappedValue );
322+ }
289323 }
290324
291325 @ ExportLibrary (InteropLibrary .class )
0 commit comments