[Slapt-get-devel] Speed up MD5 parsing
Ondrej Zary
linux at rainbow-software.org
Thu Jul 28 18:05:46 EDT 2005
Hello,
the attached patch speeds up MD5 parsing in slapt-get 0.9.10a. It does
so by only walking the checksum file once (current implementation walks
the file for *each* package - very slow). The slower system, the more
noticeable the speedup is.
--
Ondrej Zary
-------------- next part --------------
--- slapt-get-0.9.10a/src/package.c 2005-07-25 20:51:51.000000000 +0200
+++ slapt-get-0.9.10a-patched/src/package.c 2005-07-29 00:00:54.000000000 +0200
@@ -954,24 +954,27 @@
return pkg_not_excluded;
}
-void slapt_get_md5sum(slapt_pkg_info_t *pkg,FILE *checksum_file)
+void slapt_get_md5sums(struct slapt_pkg_list *pkgs,unsigned int pkg_count,
+ FILE *checksum_file)
{
slapt_regex md5sum_regex;
ssize_t getline_read;
size_t getline_len = 0;
char *getline_buffer = NULL;
+ unsigned int a;
slapt_init_regex(&md5sum_regex,SLAPT_MD5SUM_REGEX);
while ((getline_read = getline(&getline_buffer,&getline_len,
checksum_file)) != EOF) {
- /* ignore if it is not our package */
- if (strstr(getline_buffer,pkg->name) == NULL)
- continue;
- if (strstr(getline_buffer,pkg->version) == NULL)
- continue;
- if (strstr(getline_buffer,pkg->file_ext) == NULL)
+ printf("%c\b",slapt_spinner());
+
+ if (
+ (strstr(getline_buffer,".tgz") == NULL) &&
+ (strstr(getline_buffer,".tlz") == NULL) &&
+ (strstr(getline_buffer,".tbz") == NULL)
+ )
continue;
if (strstr(getline_buffer,".asc") != NULL)
continue;
@@ -1027,22 +1030,21 @@
version[md5sum_regex.pmatch[4].rm_eo - md5sum_regex.pmatch[4].rm_so] = '\0';
/* see if we can match up name, version, and location */
- if (
- (strcmp(pkg->name,name) == 0) &&
- (slapt_cmp_pkg_versions(pkg->version,version) == 0) &&
- (strcmp(pkg->location,location) == 0)
- ) {
- #if SLAPT_DEBUG == 1
- printf("%s-%s@%s, %s-%s@%s: %s\n",
- pkg->name,pkg->version,pkg->location,name,version,location,sum);
- #endif
- memcpy(pkg->md5,
- sum,md5sum_regex.pmatch[1].rm_eo - md5sum_regex.pmatch[1].rm_so + 1
- );
- free(name);
- free(version);
- free(location);
- break;
+ for (a = 0;a < pkg_count;a++) {
+ if (
+ (strcmp(pkgs->pkgs[a]->name,name) == 0) &&
+ (slapt_cmp_pkg_versions(pkgs->pkgs[a]->version,version) == 0) &&
+ (strcmp(pkgs->pkgs[a]->location,location) == 0)
+ ) {
+ #if SLAPT_DEBUG == 1
+ printf("%s-%s@%s, %s-%s@%s: %s\n",
+ pkgs->pkgs[a]->name,pkgs->pkgs[a]->version,pkgs->pkgs[a]->location,name,version,location,sum);
+ #endif
+ memcpy(pkgs->pkgs[a]->md5,
+ sum,md5sum_regex.pmatch[1].rm_eo - md5sum_regex.pmatch[1].rm_so + 1
+ );
+ break;
+ }
}
free(name);
@@ -1054,9 +1056,6 @@
if (getline_buffer)
free(getline_buffer);
- #if SLAPT_DEBUG == 1
- printf("%s-%s@%s = %s\n",pkg->name,pkg->version,pkg->location,pkg->md5);
- #endif
slapt_free_regex(&md5sum_regex);
rewind(checksum_file);
@@ -1911,20 +1910,14 @@
global_config->sources->url[i]);
if (tmp_checksum_f != NULL) {
- unsigned int a;
/* now map md5 checksums to packages */
printf(gettext("Reading Package Lists..."));
- for (a = 0;a < available_pkgs->pkg_count;a++) {
- slapt_get_md5sum(available_pkgs->pkgs[a],tmp_checksum_f);
- printf("%c\b",slapt_spinner());
- }
- if (patch_pkgs) {
- for (a = 0;a < patch_pkgs->pkg_count;a++) {
- slapt_get_md5sum(patch_pkgs->pkgs[a],tmp_checksum_f);
- printf("%c\b",slapt_spinner());
- }
- }
+ slapt_get_md5sums(available_pkgs, available_pkgs->pkg_count,
+ tmp_checksum_f);
+ if (patch_pkgs)
+ slapt_get_md5sums(patch_pkgs, patch_pkgs->pkg_count,
+ tmp_checksum_f);
printf(gettext("Done\n"));
/* write package listings to disk */
More information about the Slapt-get-devel
mailing list