Skip to content
Snippets Groups Projects
Commit 73b5c745 authored by Jonathan Schöbel's avatar Jonathan Schöbel
Browse files

Attr: added unsafe getter & setter for name

When used with care, it is possible to bypass many strdup calls.
To also save the instructions for the call, which are a lot of overhead
now, link time optimization is turned on. (-flto)
parent bf1bb1e7
No related branches found
No related tags found
No related merge requests found
...@@ -43,8 +43,8 @@ FILE_NAME_10=2022;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp ...@@ -43,8 +43,8 @@ FILE_NAME_10=2022;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp
FILE_NAME_11=2558;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ffragment_class.c;0;8 FILE_NAME_11=2558;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ffragment_class.c;0;8
FILE_NAME_12=2167;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.c;0;8 FILE_NAME_12=2167;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.c;0;8
FILE_NAME_13=5930;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.h;0;8 FILE_NAME_13=5930;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.h;0;8
FILE_NAME_14=5104;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.c;0;8 FILE_NAME_14=4656;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.c;0;8
FILE_NAME_15=2279;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.h;0;8 FILE_NAME_15=2396;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.h;0;8
FILE_NAME_16=25820;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext.c;0;8 FILE_NAME_16=25820;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext.c;0;8
FILE_NAME_17=904;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext.h;0;8 FILE_NAME_17=904;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext.h;0;8
FILE_NAME_18=1779;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator.c;0;8 FILE_NAME_18=1779;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator.c;0;8
...@@ -59,7 +59,7 @@ FILE_NAME_26=533;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2 ...@@ -59,7 +59,7 @@ FILE_NAME_26=533;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2
FILE_NAME_27=1085;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_cms.c;0;8 FILE_NAME_27=1085;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_cms.c;0;8
FILE_NAME_28=3283;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_data.c;0;8 FILE_NAME_28=3283;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_data.c;0;8
FILE_NAME_29=8770;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_node_fragment.c;0;8 FILE_NAME_29=8770;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_node_fragment.c;0;8
FILE_NAME_30=8032;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_attr.c;0;8 FILE_NAME_30=8277;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_attr.c;0;8
FILE_NAME_31=11068;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text.c;0;8 FILE_NAME_31=11068;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text.c;0;8
FILE_NAME_32=5744;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator.c;0;8 FILE_NAME_32=5744;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator.c;0;8
FILE_NAME_33=165;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftodo.txt;0;8 FILE_NAME_33=165;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftodo.txt;0;8
......
## Process this file with automake to produce Makefile.in ## Process this file with automake to produce Makefile.in
AM_CFLAGS = -Wall -Wextra -Wno-nonnull AM_CFLAGS = -Wall -Wextra -Wno-nonnull -flto
lib_LTLIBRARIES = libsefht.la lib_LTLIBRARIES = libsefht.la
......
...@@ -173,6 +173,25 @@ SH_Attr_free (/*@only@*/ struct SH_Attr * attr) ...@@ -173,6 +173,25 @@ SH_Attr_free (/*@only@*/ struct SH_Attr * attr)
return; return;
} }
static inline
/*@observer@*/
char *
get_name (const struct SH_Attr * attr)
/*@*/
{
return attr->name;
}
static inline
void
set_name (struct SH_Attr * attr, char * name)
/*@modifies attr->name@*/
{
free (attr->name);
attr->name = name;
return;
}
/*@null@*/ /*@null@*/
/*@only@*/ /*@only@*/
char * char *
...@@ -182,7 +201,7 @@ SH_Attr_get_name (const struct SH_Attr * attr, ...@@ -182,7 +201,7 @@ SH_Attr_get_name (const struct SH_Attr * attr,
{ {
char * name; char * name;
name = strdup (attr->name); name = strdup (get_name (attr));
if (NULL == name) if (NULL == name)
{ {
set_status (status, E_ALLOC, 3, "strdup failed"); set_status (status, E_ALLOC, 3, "strdup failed");
...@@ -208,13 +227,28 @@ SH_Attr_set_name (struct SH_Attr * attr, ...@@ -208,13 +227,28 @@ SH_Attr_set_name (struct SH_Attr * attr,
return FALSE; return FALSE;
} }
free (attr->name); set_name (attr, name_copy);
attr->name = name_copy;
set_success (status); set_success (status);
return TRUE; return TRUE;
} }
/*@observer@*/
const char *
SH_Attr_raw_get_name (const struct SH_Attr * attr)
/*@*/
{
return get_name (attr);
}
void
SH_Attr_raw_set_name (struct SH_Attr * attr, /*@only@*/ char * name)
/*@modifies attr->name@*/
{
set_name (attr, name);
return;
}
/*@null@*/ /*@null@*/
/*@only@*/ /*@only@*/
char * char *
......
...@@ -84,6 +84,15 @@ SH_Attr_set_name (SH_Attr * attr, ...@@ -84,6 +84,15 @@ SH_Attr_set_name (SH_Attr * attr,
/*@null@*/ /*@out@*/ struct SH_Status * status) /*@null@*/ /*@out@*/ struct SH_Status * status)
/*@modifies attr@*/; /*@modifies attr@*/;
/*@observer@*/
const char *
SH_Attr_raw_get_name (const SH_Attr * attr)
/*@*/;
void
SH_Attr_raw_set_name (SH_Attr * attr, /*@only@*/ char * name)
/*@modifies attr@*/;
/*@null@*/ /*@null@*/
/*@only@*/ /*@only@*/
char * char *
......
...@@ -327,6 +327,32 @@ START_TEST(test_attr_name_with_status) ...@@ -327,6 +327,32 @@ START_TEST(test_attr_name_with_status)
} }
END_TEST END_TEST
START_TEST(test_attr_name_raw)
{
struct SH_Attr * attr;
char * name1 = strdup ("name1");
char * name2 = strdup ("name2");
const char * name;
attr = SH_Attr_raw_new (name1, NULL, NULL);
ck_assert_ptr_ne (NULL, attr);
ck_assert_ptr_eq (name1, attr->name);
name = SH_Attr_raw_get_name (attr);
ck_assert_ptr_ne (NULL, name);
ck_assert_ptr_eq (name1, name);
SH_Attr_raw_set_name (attr, name2);
ck_assert_ptr_eq (name2, attr->name);
name = SH_Attr_raw_get_name (attr);
ck_assert_ptr_ne (NULL, name);
ck_assert_ptr_eq (name2, name);
SH_Attr_free (attr);
}
END_TEST
START_TEST(test_attr_value_no_status) START_TEST(test_attr_value_no_status)
{ {
struct SH_Attr * attr; struct SH_Attr * attr;
...@@ -437,6 +463,7 @@ Suite * test_suite (void) ...@@ -437,6 +463,7 @@ Suite * test_suite (void)
tcase_add_test (tc_core, test_attr_name_no_status); tcase_add_test (tc_core, test_attr_name_no_status);
tcase_add_test (tc_core, test_attr_name_with_status); tcase_add_test (tc_core, test_attr_name_with_status);
tcase_add_test (tc_core, test_attr_name_raw);
tcase_add_test (tc_core, test_attr_value_no_status); tcase_add_test (tc_core, test_attr_value_no_status);
tcase_add_test (tc_core, test_attr_value_with_status); tcase_add_test (tc_core, test_attr_value_with_status);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment