Skip to content

Commit

Permalink
ptp2: make ptp_add_event(s) cleaner and more performant
Browse files Browse the repository at this point in the history
  • Loading branch information
axxel authored and msmeissn committed Sep 25, 2024
1 parent d75762e commit 8d4975f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
23 changes: 9 additions & 14 deletions camlibs/ptp2/ptp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 (&params->events, &params->nrofevents, evt);
/*
params->events = realloc(params->events, sizeof(PTPContainer)*(params->nrofevents+1));
memcpy (&params->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;i<nrevents;i++) {
CHECK_PTP_RC (ptp_add_event_queue (&params->events, &params->nrofevents, &evt[i]));
}
memcpy (&params->events[params->nrofevents], events, count*sizeof(PTPContainer));
params->nrofevents += count;
return PTP_RC_OK;
}

Expand Down
4 changes: 2 additions & 2 deletions camlibs/ptp2/ptp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8d4975f

Please sign in to comment.