From 8d4975f52cda61347ac1cfdc3d8029f4ab30d03a Mon Sep 17 00:00:00 2001 From: axxel Date: Wed, 25 Sep 2024 10:51:55 +0200 Subject: [PATCH] ptp2: make ptp_add_event(s) cleaner and more performant --- camlibs/ptp2/ptp.c | 23 +++++++++-------------- camlibs/ptp2/ptp.h | 4 ++-- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/camlibs/ptp2/ptp.c b/camlibs/ptp2/ptp.c index ae8132a84..4b924d96c 100644 --- a/camlibs/ptp2/ptp.c +++ b/camlibs/ptp2/ptp.c @@ -3257,27 +3257,22 @@ ptp_add_event_queue (PTPContainer **events, unsigned int *nrevents, PTPContainer (*nrevents)++; return PTP_RC_OK; } + uint16_t -ptp_add_event (PTPParams *params, PTPContainer *evt) +ptp_add_event (PTPParams *params, PTPContainer *event) { - return ptp_add_event_queue (¶ms->events, ¶ms->nrofevents, evt); -/* - params->events = realloc(params->events, sizeof(PTPContainer)*(params->nrofevents+1)); - memcpy (¶ms->events[params->nrofevents],evt,1*sizeof(PTPContainer)); - params->nrofevents += 1; - - return PTP_RC_OK; -*/ + return ptp_add_events (params, event, 1); } uint16_t -ptp_add_events (PTPParams *params, PTPContainer *evt, unsigned int nrevents) +ptp_add_events (PTPParams *params, PTPContainer *events, unsigned int count) { - unsigned int i; + params->events = realloc(params->events, sizeof(PTPContainer)*(count+params->nrofevents)); + if (!params->events) + return PTP_RC_GeneralError; - for (i=0;ievents, ¶ms->nrofevents, &evt[i])); - } + memcpy (¶ms->events[params->nrofevents], events, count*sizeof(PTPContainer)); + params->nrofevents += count; return PTP_RC_OK; } diff --git a/camlibs/ptp2/ptp.h b/camlibs/ptp2/ptp.h index 3ea4fc98b..786501dd7 100644 --- a/camlibs/ptp2/ptp.h +++ b/camlibs/ptp2/ptp.h @@ -4139,8 +4139,8 @@ uint16_t ptp_getstream (PTPParams* params, unsigned char **data, unsigned int *s uint16_t ptp_check_event (PTPParams *params); uint16_t ptp_check_event_queue (PTPParams *params); uint16_t ptp_wait_event (PTPParams *params); -uint16_t ptp_add_event (PTPParams *params, PTPContainer *evt); -uint16_t ptp_add_events (PTPParams *params, PTPContainer *evt, unsigned int nrevents); +uint16_t ptp_add_event (PTPParams *params, PTPContainer *event); +uint16_t ptp_add_events (PTPParams *params, PTPContainer *event, unsigned int count); uint16_t ptp_add_event_queue (PTPContainer **events, unsigned int *nrevents, PTPContainer *evt); int ptp_get_one_event (PTPParams *params, PTPContainer *evt); int ptp_get_one_event_by_type(PTPParams *params, uint16_t code, PTPContainer *event);