#1 Yesterday 12:01:46

vennexedu
Member
Registered: 2024-11-12
Posts: 10

Type-Casting from String to RawUTF8

Hello,

is it more efficient to type-cast from String to RawUTF8 or to use RawUTF8 directly and implement new functions that return RawUTF8? And is the performance enhancement significant or marginal? I am talking about several million conversions overall.

Edit: Is there a function in TTextWriter that takes a string as an argument and converts it to RawUTF8 internally? I just want to avoid all the warning about implicit type conversions.

Last edited by vennexedu (Yesterday 12:16:07)

Offline

#2 Yesterday 12:55:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,649
Website

Re: Type-Casting from String to RawUTF8

For raw process, using RawUtf8 (or Utf8String) is faster, and avoid most allocations and conversions.
The performance is measurable on a server, especially with multi-threaded process. On a VCL client/app, I don't think it would make a noticeable difference.

A simple rule would be: use RawUtf8 everywhere in your business logic, and use string only when you reach the VCL/UI layer, or some external/legacy code.

You have TTextWriter.AddNoJsonEscapeString() which would make the UTF-8 conversion on the fly, with no temporary allocation.

Offline

#3 Yesterday 13:47:17

vennexedu
Member
Registered: 2024-11-12
Posts: 10

Re: Type-Casting from String to RawUTF8

Thank you! In now use TTextWriter.AddNoJsonEscapeString() instead of AddString and the conversion warnings are gone. I also found AddComma, so instead of writing '),', I can simply use Add(')') and then AddComma. AddNull also comes in handy.

Offline

Board footer

Powered by FluxBB