shithub: alienpatch

Download patch

ref: 3af6f124c7d2c858c252c839ec043ffd7a4a5f7a
parent: 85a22730dfc0b6c3e4de7c44517939f2ac3ed66d
author: qwx <qwx@sciops.net>
date: Tue Dec 20 10:12:15 EST 2022

add ft2-clone-dirread: initial hack to fix directory reads abysmal speed

unicharToCp437 seems to be the bottleneck here

--- /dev/null
+++ b/ft2-clone-dirread
@@ -1,0 +1,97 @@
+diff fde50d93b2284178743a12e8c359286ea99f0b21 uncommitted
+--- a/src/ft2_diskop.c
++++ b/src/ft2_diskop.c
+@@ -1565,14 +1565,15 @@
+ {
+ 	DirRec *dirEntry = &FReq_Buffer[rad];
+ 
+-	char *name = unicharToCp437(dirEntry->nameU, true);
+-	if (name == NULL)
+-		return NULL;
++	//char *name = unicharToCp437(dirEntry->nameU, true);
++	//if (name == NULL)
++	//	return NULL;
++	char *name = dirEntry->nameU;
+ 
+ 	const int32_t nameLen = (int32_t)strlen(name);
+ 	if (nameLen == 0)
+ 	{
+-		free(name);
++		//free(name);
+ 		return NULL;
+ 	}
+ 
+@@ -1579,7 +1580,7 @@
+ 	char *p = (char *)malloc(nameLen+1+1);
+ 	if (p == NULL)
+ 	{
+-		free(name);
++		//free(name);
+ 		return NULL;
+ 	}
+ 
+@@ -1594,7 +1595,7 @@
+ 
+ 		strcpy(&p[1], name);
+ 
+-		free(name);
++		//free(name);
+ 		return p;
+ 	}
+ 	else
+@@ -1606,7 +1607,7 @@
+ 		{
+ 			// sort by filename
+ 			strcpy(p, name);
+-			free(name);
++			//free(name);
+ 			return p;
+ 		}
+ 		else
+@@ -1616,7 +1617,7 @@
+ 			if (extLen <= 1)
+ 			{
+ 				strcpy(p, name);
+-				free(name);
++				//free(name);
+ 				return p;
+ 			}
+ 
+@@ -1625,12 +1626,27 @@
+ 			memcpy(&p[extLen-1], name, i);
+ 			p[nameLen-1] = '\0';
+ 
+-			free(name);
++			//free(name);
+ 			return p;
+ 		}
+ 	}
+ }
+ 
++static int dcmp(void *a, void *b)
++{
++	DirRec *d, *e;
++	char *n, *m;
++
++	// FIXME: reimplement dcmp with the stuff the rest does
++	d = a;
++	e = b;
++	//n = d->nameU;//unicharToCp437(d->nameU, true);
++	//m = e->nameU;//unicharToCp437(e->nameU, true);
++	n = ach(d - FReq_Buffer);
++	m = ach(e - FReq_Buffer);
++	return _stricmp(n, m);
++}
++
+ static void sortDirectory(void)
+ {
+ 	bool didSwap;
+@@ -1637,6 +1653,8 @@
+ 
+ 	if (FReq_FileCount < 2)
+ 		return; // no need to sort
++	qsort(FReq_Buffer, FReq_FileCount, sizeof *FReq_Buffer, dcmp);
++	return;
+ 
+ 	uint32_t offset = FReq_FileCount >> 1;
+ 	while (offset > 0)