<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">On 12/11/2025 11:14, Liam Miller-Cushon
wrote:<br>
</div>
<blockquote type="cite" cite="mid:CAL4Qsgt+25v=t_DqcDbZ56vEj_wv=QaLCWKT=bR5SVPZJRpc1Q@mail.gmail.com">
<div dir="ltr">
<div class="gmail_quote gmail_quote_container">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<p>I believe what you mean here is that if I have a
string, and I want to copy to a destination segment I
could either:</p>
<p>* if the string buffer is compatible, just bulk-copy
that buffer into the target segment<br>
* if the string buffer is not compatible, encode the
string _directly_ into the target segment</p>
<p>Correct? If so, I tend to agree this would be slightly
preferrable, as we'd be touching things only once. And,
I believe this can be also done to the existing
setString method?</p>
</div>
</blockquote>
<div>I think that's right, but I'd also gotten slightly
confused. To try to restate:</div>
<div><br>
</div>
<div>setString assumes \0, which I touched on in the original
mail about not being ideal if you want to write non-\0
terminated strings and the output buffer is perfectly sized.</div>
</div>
</div>
</blockquote>
<blockquote type="cite" cite="mid:CAL4Qsgt+25v=t_DqcDbZ56vEj_wv=QaLCWKT=bR5SVPZJRpc1Q@mail.gmail.com">
<div dir="ltr">
<div class="gmail_quote gmail_quote_container">
<div><br>
</div>
<div>In the case where the bytes aren't compatible, setString
currently falls back to getBytes and then copies that into
the destination segment. But I think it could be optimized
to encode directly to the output without changing the API.</div>
</div>
</div>
</blockquote>
Yes, I think we understood each other -- that's what I meant by "I
believe this can be also done to the existing setString method"
<blockquote type="cite" cite="mid:CAL4Qsgt+25v=t_DqcDbZ56vEj_wv=QaLCWKT=bR5SVPZJRpc1Q@mail.gmail.com">
<div dir="ltr">
<div class="gmail_quote gmail_quote_container">
<div><br>
</div>
<div>I had thought your proposal was to support the use-case
of writing non-\0 terminated strings by using MS::ofString
and then MS::copy, which I think would have equivalent
performance to setString for the bytes compatible case, but
might be more constrained for the case where the bytes
aren't compatible. Had I misunderstood that part?</div>
</div>
</div>
</blockquote>
<p>For the non-\0 terminated strings, you have the String-based
MemorySegment::copy I described - e.g.</p>
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang=""><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">void copy(String srcString, Charset srcCharset, int srcIndex, MemorySegment dstSegment, long dstOffset, int length);</span></pre></pre>
<p></p>
<p><br>
</p>
<p>With this, we also have two cases:</p>
<p>* if the charset is compatible with the string buffer, we just
bulk-copy the string buffer (or a portion of it) into the dest
segment<br>
* otherwise we can encode the srcString directly into the dest
segment</p>
<p>Maurizio<br>
</p>
</body>
</html>