') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); GitHub - Codain/FIOL: Fast Input/Output Library · GitHub
Skip to content

Latest commit

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

FIOL

Fast Input/Output Library

Why this library?

Standard libraries exists since decades but for some applications they have disadvantages:

  • Performances. Most of them are generic, not specialized, and thus may have some un-needed features (but which consumes CPU);
  • Access to source code of their implementations (for customisation, certification, performance improvement...).

Standard functions referenced here are sscanf, atoi, _atoi...

And what about performances? Is it really better than standard functions?

A benchmark folder exists. The better is to test by yourself.

Benchmarks usually show between x2 and x10 gains.

It looks to good to be true... any limitation? Drawback?

Of course if this library is more efficient than standard functions there is a reason...

  1. This library handles only decimal numbers (no way to change the base as in strtol);
  2. This library does not implement safety checks on the data to read/write (e.g. it is not thread-safe);
  3. This library does not reimplement the performance-killer (but comfortable to use) patterns of the printf family functions (printf, sprintf...).

How to use?

Functions are named with a pattern:

"fiol" <format> <action> <type>

With:

  • format: 'B' for binary format, 'S' for string format
  • action: 'Read' or 'Write'
  • Type: 'Int', 'UInt' for an unsigned integer...

For instance fiolSReadFixedInt means that we ask FIOL to read ('Read') from a string ('S') a maximum number of chars ('fixed') and to store them as an integer ('Int').

Each function return the number of bytes/chars read or writen. This can be used to:

  • Detect an error (if it returned 0);
  • Implment a cursor mechanism on a buffer.

To read an unsigned short int in Big Endian format from a binary buffer:

unsigned char* cursor = ...; // The cursor
uint16_t uint16 = 0;
fiolBReadU16BE(cursor, &uint16);

To read an unsigned short int in Big Endian format from a binary buffer AND retrieve number of bytes read (but not move the cursor) :

unsigned char* cursor = ...; // The cursor
uint16_t uint16 = 0;
length = fiolBReadU16BE(cursor, &uint16);

To read an unsigned short int in Big Endian format from a binary buffer AND retrieve number of bytes read AND move cursor to the next byte :

unsigned char* cursor = ...; // The cursor
uint16_t uint16 = 0;
cursor += (length = fiolBReadU16BE(cursor, &uint16));

List of equivalences

To read from a string

Standard functionExampleFIOL equivalent of the example
atofval = atof(str);fiolSReadFloat(str, &val);
atoival = atoi(str);fiolSReadInt(str, &val);
atolval = atol(str);fiolSReadInt(str, &val);
sscanfsscanf(str, "%d", &val);fiolSReadInt(str, &val);
sscanfsscanf(str, "%d %d", &val1, &val2);str += fiolSReadInt(str, &val1); str += fiolSReadChar(str, 0); str += fiolSReadInt(str, &val2);
strtodval = strtod(str, 0);fiolSReadFloat(str, &val);
strtolval = strtol(str, 0, 10);fiolSReadInt(str, &val);

To write to a string

Standard functionExampleFIOL equivalent of the example
itoaitoa(val, str, 10);fiolSWriteInt(str, val);
sprintfsprintf(str, "%d", val);fiolSWriteInt(str, val);
sprintfsprintf(str, "%d %d", val1, val2);str += fiolSWriteInt(str, &val1); str += fiolSWriteChar(str, ' '); str += fiolSWriteInt(str, &val2);

About

Fast Input/Output Library

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages