Turning lowers to uppers without a branch

In another comment of the Curiouser Case, Arnaud Bouchez pointed to an interesting optimization that is use in mORMot‘s UpperCopy255Buf function: a branchless parallel upper case conversion.

At the core of that implementation are the following lines of code

c := src[i];
d := c or _80;
dest[i] := c - ((d - _61) and not (d - _7b)) and ((not c) and _80) shr 2;

Ok, it may not be too obvious what happens at first sight. Let’s break it down.

The Mischievous Case-Insensitive Hash

In a comment to the previous article on a case insensitive hash code, Stefan Glienke pointed to an approach used in Spring4D’s comparers, which is a delightful hack.

Rather than converting the string to a “proper lower case”, it converts the string to an “approximate lower case” using an “or $20”, which happens to be good enough for a hash on string identifiers.

To figure the trick, one needs to check the ASCII Table. (more…)

SQLite as a no-SQL database

SQLite offers through its JSON1 extension a lot of capability. Generating JSON outputs from SQL, even complex structured, multi-level JSON is very straightforward.

But what about the opposite use case ? When you have store data as JSON in an SQLite database, and you want to search or filter it ? This is a short exploration of what to expect.


Boosting Intel laptop battery life

We all need more battery life, and for quad-core i7 & i5, a simple way to gain more battery is to simply turn off extra cores.

This little setting for Windows 10 made a whole world of difference in my experience, with battery life literally doubled on my core i7, and almost 50% gains on another i5 laptop.

Disclaimer: instructions that follow are for advanced users: if you do not understand the instructions, best give up than mess your machine. For all I know, if you misstep, you may end up blowing up a hole in reality and destroy the universe. You’ve been warned.


Beware of TForm.SetBounds in a multi-monitor context

When in a multi-monitor context with monitors having varying DPI settings, TForm.SetBounds can be a little ambiguous when combined with form scaling.

The issue comes from Width / Height, in Delphi 10.3.1, they are understood as applying to the monitor the form is currently one, not the monitor SetBounds could be moving the form to. This is manifest when restoring a form position: if you store a form’s bounds, then try to restore it with SetBounds, it will result in an incorrectly sized form.


Faster backups for large SQLite databases

sqlite370_bannerDespite having “lite” in its name, SQLite can handle very large databases quite efficiently. The single largest I am currently dealing with just passed 100 GB, and occasionally when backing it up with the SQLite standard Command Line utility it would take many hours.

After some asking on the sqlite-users list (thanks Clemens Madish & Simon Slavin), and some experimenting, I have gotten the backup time down to 4-5 minutes on a live 100 GB database, which is just fine in my book. Below are the findings and an utility, sql3bak, which wraps the results of the findings.


Fuzz Testing in Delphi

Monkey-typingI am a big fan of TBCEditor by Lasse Rautiainen, in case you have not heard about it, it is fork of SynEditthat diverged very significantly and includes support for code folding, fully JSON-based syntax highlighters, minimap and many other features.

Of course a code editor is a very complex piece of software, with many opportunities for bugs to hide. I have been helping by providing some Fuzz Testing code and vectors.