node-re2 icon indicating copy to clipboard operation
node-re2 copied to clipboard

Accept `Uint8Array` / `ArrayBuffer` / `DataView` as `Buffer` for UTF-8

Open uhop opened this issue 1 month ago • 0 comments

Internally google/re2 library works with UTF-8 binary byte arrays, while JS works with UTF-16. Going back and forth requires re-coding data and recalculating offsets, which are linear operations heavy on memory. To alleviate this problem RE2 (this library) allows to use Buffer instead of a string. But Buffer is a Node-specific object. Sometimes we should interface to libraries that produce different types of objects:

  • Uint8Array
  • ArrayBuffer
  • SharedArrayBuffer
  • DataView

Returning found strings involves creating new objects and copying data even for buffers. Consider using DataView for that.

uhop avatar Dec 07 '25 15:12 uhop