libxbps: performance improvements by caching the most accessed paths.
1- We can cache the result of the first xbps_pkgdb_init() when it fails and avoid the malloc/free/access from it. 2- We cache the uname(2) result into a private var in xbps_handle and use it in xbps_pkg_arch_match(). This improves performance by ~5% approx and it's close as it was before introducing the repository index format 1.5.
This commit is contained in:
@@ -62,14 +62,17 @@ ATF_TC_HEAD(find_pkg_in_array_by_name_test, tc)
|
||||
}
|
||||
ATF_TC_BODY(find_pkg_in_array_by_name_test, tc)
|
||||
{
|
||||
struct xbps_handle xh;
|
||||
prop_array_t a;
|
||||
prop_dictionary_t dr;
|
||||
|
||||
a = prop_array_internalize(arrayxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY);
|
||||
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xbps_init(&xh);
|
||||
/* match by pkgname */
|
||||
dr = xbps_find_pkg_in_array_by_name(a, "foo", NULL);
|
||||
dr = xbps_find_pkg_in_array_by_name(&xh, a, "foo", NULL);
|
||||
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
|
||||
}
|
||||
|
||||
@@ -80,14 +83,17 @@ ATF_TC_HEAD(find_pkg_in_array_by_pattern_test, tc)
|
||||
}
|
||||
ATF_TC_BODY(find_pkg_in_array_by_pattern_test, tc)
|
||||
{
|
||||
struct xbps_handle xh;
|
||||
prop_array_t a;
|
||||
prop_dictionary_t dr;
|
||||
|
||||
a = prop_array_internalize(arrayxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY);
|
||||
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xbps_init(&xh);
|
||||
/* match by pkgpattern */
|
||||
dr = xbps_find_pkg_in_array_by_pattern(a, "foo>=2.0", NULL);
|
||||
dr = xbps_find_pkg_in_array_by_pattern(&xh, a, "foo>=2.0", NULL);
|
||||
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
|
||||
}
|
||||
|
||||
@@ -98,14 +104,17 @@ ATF_TC_HEAD(find_pkg_in_array_by_pkgver_test, tc)
|
||||
}
|
||||
ATF_TC_BODY(find_pkg_in_array_by_pkgver_test, tc)
|
||||
{
|
||||
struct xbps_handle xh;
|
||||
prop_array_t a;
|
||||
prop_dictionary_t dr;
|
||||
|
||||
a = prop_array_internalize(arrayxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY);
|
||||
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xbps_init(&xh);
|
||||
/* exact match by pkgver */
|
||||
dr = xbps_find_pkg_in_array_by_pkgver(a, "foo-2.0", NULL);
|
||||
dr = xbps_find_pkg_in_array_by_pkgver(&xh, a, "foo-2.0", NULL);
|
||||
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
|
||||
}
|
||||
|
||||
@@ -116,6 +125,7 @@ ATF_TC_HEAD(find_virtualpkg_in_array_by_name_test, tc)
|
||||
}
|
||||
ATF_TC_BODY(find_virtualpkg_in_array_by_name_test, tc)
|
||||
{
|
||||
struct xbps_handle xh;
|
||||
prop_array_t a;
|
||||
prop_dictionary_t dr;
|
||||
const char *pkgname;
|
||||
@@ -123,7 +133,9 @@ ATF_TC_BODY(find_virtualpkg_in_array_by_name_test, tc)
|
||||
a = prop_array_internalize(arrayxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY);
|
||||
|
||||
dr = xbps_find_virtualpkg_in_array_by_name(a, "virtualpkg");
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xbps_init(&xh);
|
||||
dr = xbps_find_virtualpkg_in_array_by_name(&xh, a, "virtualpkg");
|
||||
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
|
||||
prop_dictionary_get_cstring_nocopy(dr, "pkgname", &pkgname);
|
||||
ATF_REQUIRE_STREQ(pkgname, "afoo");
|
||||
@@ -136,6 +148,7 @@ ATF_TC_HEAD(find_virtualpkg_in_array_by_pattern_test, tc)
|
||||
}
|
||||
ATF_TC_BODY(find_virtualpkg_in_array_by_pattern_test, tc)
|
||||
{
|
||||
struct xbps_handle xh;
|
||||
prop_array_t a;
|
||||
prop_dictionary_t dr;
|
||||
const char *pkgname;
|
||||
@@ -143,7 +156,9 @@ ATF_TC_BODY(find_virtualpkg_in_array_by_pattern_test, tc)
|
||||
a = prop_array_internalize(arrayxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY);
|
||||
|
||||
dr = xbps_find_virtualpkg_in_array_by_pattern(a, "virtualpkg>=9999");
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xbps_init(&xh);
|
||||
dr = xbps_find_virtualpkg_in_array_by_pattern(&xh, a, "virtualpkg>=9999");
|
||||
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
|
||||
prop_dictionary_get_cstring_nocopy(dr, "pkgname", &pkgname);
|
||||
ATF_REQUIRE_STREQ(pkgname, "afoo");
|
||||
|
@@ -65,13 +65,16 @@ ATF_TC_HEAD(find_pkg_in_dict_by_name_test, tc)
|
||||
}
|
||||
ATF_TC_BODY(find_pkg_in_dict_by_name_test, tc)
|
||||
{
|
||||
struct xbps_handle xh;
|
||||
prop_dictionary_t d, dr;
|
||||
|
||||
d = prop_dictionary_internalize(dictxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
|
||||
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xbps_init(&xh);
|
||||
/* match by pkgname */
|
||||
dr = xbps_find_pkg_in_dict_by_name(d, "packages", "foo");
|
||||
dr = xbps_find_pkg_in_dict_by_name(&xh, d, "packages", "foo");
|
||||
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
|
||||
}
|
||||
|
||||
@@ -82,13 +85,16 @@ ATF_TC_HEAD(find_pkg_in_dict_by_pattern_test, tc)
|
||||
}
|
||||
ATF_TC_BODY(find_pkg_in_dict_by_pattern_test, tc)
|
||||
{
|
||||
struct xbps_handle xh;
|
||||
prop_dictionary_t d, dr;
|
||||
|
||||
d = prop_dictionary_internalize(dictxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
|
||||
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xbps_init(&xh);
|
||||
/* match by pkgpattern */
|
||||
dr = xbps_find_pkg_in_dict_by_pattern(d, "packages", "foo>=2.0");
|
||||
dr = xbps_find_pkg_in_dict_by_pattern(&xh, d, "packages", "foo>=2.0");
|
||||
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
|
||||
}
|
||||
|
||||
@@ -99,13 +105,16 @@ ATF_TC_HEAD(find_pkg_in_dict_by_pkgver_test, tc)
|
||||
}
|
||||
ATF_TC_BODY(find_pkg_in_dict_by_pkgver_test, tc)
|
||||
{
|
||||
struct xbps_handle xh;
|
||||
prop_dictionary_t d, dr;
|
||||
|
||||
d = prop_dictionary_internalize(dictxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
|
||||
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xbps_init(&xh);
|
||||
/* exact match by pkgver */
|
||||
dr = xbps_find_pkg_in_dict_by_pkgver(d, "packages", "foo-2.0_1");
|
||||
dr = xbps_find_pkg_in_dict_by_pkgver(&xh, d, "packages", "foo-2.0_1");
|
||||
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
|
||||
}
|
||||
|
||||
@@ -116,6 +125,7 @@ ATF_TC_HEAD(find_virtualpkg_in_dict_by_pattern_test, tc)
|
||||
}
|
||||
ATF_TC_BODY(find_virtualpkg_in_dict_by_pattern_test, tc)
|
||||
{
|
||||
struct xbps_handle xh;
|
||||
prop_dictionary_t d, dr;
|
||||
const char *pkgver;
|
||||
|
||||
@@ -123,12 +133,14 @@ ATF_TC_BODY(find_virtualpkg_in_dict_by_pattern_test, tc)
|
||||
ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
|
||||
|
||||
/* match virtualpkg by pattern */
|
||||
dr = xbps_find_virtualpkg_in_dict_by_pattern(d, "packages", "virtualpkg>=9999");
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xbps_init(&xh);
|
||||
dr = xbps_find_virtualpkg_in_dict_by_pattern(&xh, d, "packages", "virtualpkg>=9999");
|
||||
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
|
||||
prop_dictionary_get_cstring_nocopy(dr, "pkgver", &pkgver);
|
||||
ATF_REQUIRE_STREQ(pkgver, "afoo-1.1_1");
|
||||
|
||||
dr = xbps_find_virtualpkg_in_dict_by_pattern(d, "packages", "virtualpkg<=9999_1");
|
||||
dr = xbps_find_virtualpkg_in_dict_by_pattern(&xh, d, "packages", "virtualpkg<=9999_1");
|
||||
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
|
||||
prop_dictionary_get_cstring_nocopy(dr, "pkgver", &pkgver);
|
||||
ATF_REQUIRE_STREQ(pkgver, "afoo-1.1_1");
|
||||
@@ -141,14 +153,17 @@ ATF_TC_HEAD(find_virtualpkg_in_dict_by_name_test, tc)
|
||||
}
|
||||
ATF_TC_BODY(find_virtualpkg_in_dict_by_name_test, tc)
|
||||
{
|
||||
struct xbps_handle xh;
|
||||
prop_dictionary_t d, dr;
|
||||
const char *pkgver;
|
||||
|
||||
d = prop_dictionary_internalize(dictxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
|
||||
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xbps_init(&xh);
|
||||
/* match virtualpkg by name */
|
||||
dr = xbps_find_virtualpkg_in_dict_by_name(d, "packages", "virtualpkg");
|
||||
dr = xbps_find_virtualpkg_in_dict_by_name(&xh, d, "packages", "virtualpkg");
|
||||
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
|
||||
prop_dictionary_get_cstring_nocopy(dr, "pkgver", &pkgver);
|
||||
ATF_REQUIRE_STREQ(pkgver, "afoo-1.1_1");
|
||||
|
@@ -25,6 +25,7 @@
|
||||
*/
|
||||
#include <atf-c.h>
|
||||
#include <xbps_api.h>
|
||||
#include <string.h>
|
||||
|
||||
static const char dictxml[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
@@ -100,6 +101,7 @@ ATF_TC_HEAD(remove_pkg_from_array_by_name_test, tc)
|
||||
|
||||
ATF_TC_BODY(remove_pkg_from_array_by_name_test, tc)
|
||||
{
|
||||
struct xbps_handle xh;
|
||||
prop_array_t a;
|
||||
prop_dictionary_t d, d2;
|
||||
|
||||
@@ -109,8 +111,10 @@ ATF_TC_BODY(remove_pkg_from_array_by_name_test, tc)
|
||||
d2 = prop_dictionary_internalize(dictxml2);
|
||||
ATF_REQUIRE_EQ(prop_object_type(d2), PROP_TYPE_DICTIONARY);
|
||||
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xbps_init(&xh);
|
||||
a = prop_dictionary_get(d, "packages");
|
||||
ATF_REQUIRE_EQ(xbps_remove_pkg_from_array_by_name(a, "afoo", NULL), true);
|
||||
ATF_REQUIRE_EQ(xbps_remove_pkg_from_array_by_name(&xh, a, "afoo", NULL), true);
|
||||
ATF_REQUIRE_EQ(prop_dictionary_equals(d, d2), true);
|
||||
}
|
||||
|
||||
@@ -123,6 +127,7 @@ ATF_TC_HEAD(remove_pkg_from_array_by_pattern_test, tc)
|
||||
|
||||
ATF_TC_BODY(remove_pkg_from_array_by_pattern_test, tc)
|
||||
{
|
||||
struct xbps_handle xh;
|
||||
prop_array_t a;
|
||||
prop_dictionary_t d, d2;
|
||||
|
||||
@@ -132,8 +137,10 @@ ATF_TC_BODY(remove_pkg_from_array_by_pattern_test, tc)
|
||||
d2 = prop_dictionary_internalize(dictxml2);
|
||||
ATF_REQUIRE_EQ(prop_object_type(d2), PROP_TYPE_DICTIONARY);
|
||||
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xbps_init(&xh);
|
||||
a = prop_dictionary_get(d, "packages");
|
||||
ATF_REQUIRE_EQ(xbps_remove_pkg_from_array_by_pattern(a, "afoo>=1.0", NULL), true);
|
||||
ATF_REQUIRE_EQ(xbps_remove_pkg_from_array_by_pattern(&xh, a, "afoo>=1.0", NULL), true);
|
||||
ATF_REQUIRE_EQ(prop_dictionary_equals(d, d2), true);
|
||||
}
|
||||
|
||||
@@ -146,6 +153,7 @@ ATF_TC_HEAD(remove_pkg_from_array_by_pkgver_test, tc)
|
||||
|
||||
ATF_TC_BODY(remove_pkg_from_array_by_pkgver_test, tc)
|
||||
{
|
||||
struct xbps_handle xh;
|
||||
prop_array_t a;
|
||||
prop_dictionary_t d, d2;
|
||||
|
||||
@@ -155,8 +163,10 @@ ATF_TC_BODY(remove_pkg_from_array_by_pkgver_test, tc)
|
||||
d2 = prop_dictionary_internalize(dictxml2);
|
||||
ATF_REQUIRE_EQ(prop_object_type(d2), PROP_TYPE_DICTIONARY);
|
||||
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xbps_init(&xh);
|
||||
a = prop_dictionary_get(d, "packages");
|
||||
ATF_REQUIRE_EQ(xbps_remove_pkg_from_array_by_pkgver(a, "afoo-1.1_1", NULL), true);
|
||||
ATF_REQUIRE_EQ(xbps_remove_pkg_from_array_by_pkgver(&xh, a, "afoo-1.1_1", NULL), true);
|
||||
ATF_REQUIRE_EQ(prop_dictionary_equals(d, d2), true);
|
||||
}
|
||||
|
||||
@@ -169,6 +179,7 @@ ATF_TC_HEAD(remove_string_from_array_test, tc)
|
||||
|
||||
ATF_TC_BODY(remove_string_from_array_test, tc)
|
||||
{
|
||||
struct xbps_handle xh;
|
||||
prop_array_t a, a2;
|
||||
|
||||
a = prop_array_internalize(axml);
|
||||
@@ -177,7 +188,9 @@ ATF_TC_BODY(remove_string_from_array_test, tc)
|
||||
a2 = prop_array_internalize(axml2);
|
||||
ATF_REQUIRE_EQ(prop_object_type(a2), PROP_TYPE_ARRAY);
|
||||
|
||||
ATF_REQUIRE_EQ(xbps_remove_string_from_array(a, "foo-1.0_1"), true);
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xbps_init(&xh);
|
||||
ATF_REQUIRE_EQ(xbps_remove_string_from_array(&xh, a, "foo-1.0_1"), true);
|
||||
ATF_REQUIRE_EQ(prop_array_equals(a, a2), true);
|
||||
}
|
||||
|
||||
@@ -190,6 +203,7 @@ ATF_TC_HEAD(remove_pkgname_from_array_test, tc)
|
||||
|
||||
ATF_TC_BODY(remove_pkgname_from_array_test, tc)
|
||||
{
|
||||
struct xbps_handle xh;
|
||||
prop_array_t a, a2;
|
||||
|
||||
a = prop_array_internalize(axml);
|
||||
@@ -198,7 +212,9 @@ ATF_TC_BODY(remove_pkgname_from_array_test, tc)
|
||||
a2 = prop_array_internalize(axml2);
|
||||
ATF_REQUIRE_EQ(prop_object_type(a2), PROP_TYPE_ARRAY);
|
||||
|
||||
ATF_REQUIRE_EQ(xbps_remove_pkgname_from_array(a, "foo"), true);
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xbps_init(&xh);
|
||||
ATF_REQUIRE_EQ(xbps_remove_pkgname_from_array(&xh, a, "foo"), true);
|
||||
ATF_REQUIRE_EQ(prop_array_equals(a, a2), true);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user