Color Theme, JSON and Cleanup
Soon I'll be writing UI code for displaying source files and editing text. I wanted syntax highlighting to look right, so I started with something easy. I added code to detect the system theme, and if it changes while the program is open, it'll dynamically change the theme. If I didn't do this, manually changing themes in code would have annoyed me. Next, I looked at the data LSPs give for syntax highlighting. They hand you a large array with many ints, mostly small digits. I wrote my own JSON parser (the biggest reason is that I'll need an optimized json parser in a later project) and wrote a function for this case. It ran extremely quickly, unless I compiled with clang, which failed to inline a two-line function (yes really, two lines). Fortunately, using unlikely/__builtin_expect solved the problem.
Next, I wrote bookkeeping code for which files are opened. Ironically, I don't want the background thread to block. My main thread tells the background thread to load a file, which ask the IO thread to load (because OSes don't fully support async io), which after loading, sends it to a worker pool to scan the contents (how many newlines in the file, some info for code folding, etc), which then forward it to the main thread. Surprisingly, it's only about 30 lines of simple code. 5 to start it (or 1 if I want a long line), 15 for the background and worker thread, then another 10 when the main thread receives the results. I don't count lines in async file load or the scan code because they were written for other functions to use, such as loading a non-source file and scanning a paste.
After that, I wrote small functions like getting the extension from a filename, and getting a pointer in my hashmap instead of a reference. Last, I deleted code I wasn't using and improved function signatures.