Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored prival from string for performance #437

Merged
merged 17 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/facility.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ stumpless_get_facility_enum_from_buffer(const char *facility_buffer, size_t faci
size_t i;
char *facility_name;
const int str_offset = 19; // to ommit "STUMPLESS_FACILITY_"
size_t buf_length;

facility_bound = sizeof( facility_enum_to_string ) /
sizeof( facility_enum_to_string[0] );

facility_name = copy_cstring_with_length(facility_buffer, &buf_length);
facility_name = copy_cstring_length(facility_buffer, facility_buffer_length);
if( !facility_name ) {
return -1;
}
Expand Down
25 changes: 4 additions & 21 deletions src/prival.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
#include <stumpless/prival.h>
#include <stumpless/severity.h>
#include <stumpless/facility.h>
#include <stumpless/error.h>
#include "private/config.h"
#include "private/config/wrapper/locale.h"
#include "private/error.h"
#include "private/facility.h"
#include "private/memory.h"
#include "private/prival.h"
#include "private/severity.h"
#include "private/strhelper.h"
#include "private/validate.h"

const char *
Expand Down Expand Up @@ -64,7 +64,6 @@ stumpless_prival_from_string( const char *string ) {
int prival;
int severity;
int facility;
const char *param;
const char *period;
const char *sec_period;
size_t len;
Expand Down Expand Up @@ -103,15 +102,7 @@ stumpless_prival_from_string( const char *string ) {
// Calculate the facility length, up to the first period character
len = period - string;

// Copy the facility substring to the param buffer
param = copy_cstring_length( string, len );
if( !param ) {
return -1;
}

facility = stumpless_get_facility_enum( param );

free_mem( param );
facility = stumpless_get_facility_enum_from_buffer( string, len );

if( facility < 0 ) {
raise_invalid_param( );
Expand All @@ -122,17 +113,9 @@ stumpless_prival_from_string( const char *string ) {
len++;
len = slen - len;

// Copy the severity substring to the param buffer
param = copy_cstring_length( period + 1, len );
if( !param ) {
return -1;
}

severity = stumpless_get_severity_enum( param );

free_mem( param );
severity = stumpless_get_severity_enum_from_buffer( period + 1, len );

if( severity < 0 ) {
if( severity < 0 && !stumpless_has_error()) {
Griezn marked this conversation as resolved.
Show resolved Hide resolved
raise_invalid_param( );
return -1;
}
Expand Down
3 changes: 1 addition & 2 deletions src/severity.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ enum stumpless_severity stumpless_get_severity_enum_from_buffer(const char *seve
size_t i;
char *severity_name;
const int str_offset = 19; // to ommit "STUMPLESS_SEVERITY_"
size_t buf_length;

severity_bound = sizeof( severity_enum_to_string ) /
sizeof( severity_enum_to_string[0] );

severity_name = copy_cstring_with_length( severity_buffer, &buf_length );
severity_name = copy_cstring_length( severity_buffer, severity_buffer_length );
if( !severity_name ) {
return -1;
}
Expand Down