Skip to content

Instantly share code, notes, and snippets.

View ledbit's full-sized avatar

Ledion Bitincka ledbit

View GitHub Profile
@ledbit
ledbit / write.js
Last active February 14, 2022 12:29
nodejs buffer string write performance
'use strict';
function writeUTF8ToBuf(str, buf, off=0) {
for (let i=0; i < str.length; i++) {
const charcode = str.charCodeAt(i);
if (charcode < 0x80) buf[off++] = charcode;
else if (charcode < 0x800) {
buf[off++] = 0xc0 | (charcode >> 6);
buf[off++] = 0x80 | (charcode & 0x3f);