Changeset 58677f97 in OpenModelica


Ignore:
Timestamp:
2022-05-16T16:57:03+02:00 (2 years ago)
Author:
Philip Hannebohm <phannebohm@…>
Children:
dea6384f
Parents:
caa3fcca
Message:

[janitor] Refactor listPop in list.c

Location:
OMCompiler/SimulationRuntime/c
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • OMCompiler/SimulationRuntime/c/simulation/solver/events.c

    rcaa3fcca r58677f97  
    355355  while(listLen(&tmpEventList) > 0)
    356356  {
    357     /* TODO do this directly w/o free-malloc */
    358357    long event_id = *((long*)listFirstData(&tmpEventList));
    359     listPopFront(&tmpEventList);
    360     listPushFront(eventList, &event_id);
    361 
     358    listPushFrontNodeNoCopy(eventList, listPopFrontNode(&tmpEventList));
    362359    infoStreamPrint(LOG_ZEROCROSSINGS, 0, "Event id: %ld", event_id);
    363360  }
  • OMCompiler/SimulationRuntime/c/simulation/solver/nonlinearValuesList.c

    r83be5f2b r58677f97  
    7575    {
    7676      elem = (VALUE*) listFirstData(tmpList->valueList);
    77       listPopFront(tmpList->valueList);
     77      listRemoveFront(tmpList->valueList);
    7878    }
    7979    freeList(tmpList->valueList);
  • OMCompiler/SimulationRuntime/c/simulation/solver/synchronous.c

    r30bf2469 r58677f97  
    292292    type = nextTimer->type;
    293293    activationTime = nextTimer->activationTime;
    294     listPopFront(data->simulationInfo->intvlTimers);
     294    listRemoveFront(data->simulationInfo->intvlTimers);
    295295    switch(type)
    296296    {
     
    375375    type = nextTimer->type;
    376376    activationTime = nextTimer->activationTime;
    377     listPopFront(data->simulationInfo->intvlTimers);
     377    listRemoveFront(data->simulationInfo->intvlTimers);
    378378    switch(type)
    379379    {
  • OMCompiler/SimulationRuntime/c/util/list.c

    rcaa3fcca r58677f97  
    9090}
    9191
     92/**
     93 * @brief Pushes node to the front of list
     94 *
     95 * @param list    Pointer to list
     96 * @param node    Pointer to node (will not be copied)
     97 */
     98void listPushFrontNodeNoCopy(LIST *list, LIST_NODE *node)
     99{
     100  assertStreamPrint(NULL, 0 != list, "invalid list-pointer");
     101  assertStreamPrint(NULL, 0 != node, "invalid list-node");
     102
     103  node->next = list->first;
     104  ++(list->length);
     105  list->first = node;
     106  if(!list->last)
     107    list->last = list->first;
     108}
     109
    92110void listPushBack(LIST *list, const void *data)
    93111{
     
    151169}
    152170
    153 void listPopFront(LIST *list)
    154 {
    155   if(list)
     171/**
     172 * @brief Return first node and pop from list
     173 *
     174 * @param list    Pointer to list
     175 * @return node   Pointer to node (must be freed by caller)
     176 */
     177LIST_NODE *listPopFrontNode(LIST *list)
     178{
     179  assertStreamPrint(NULL, 0 != list, "invalid list-pointer");
     180  assertStreamPrint(NULL, 0 != list->first, "empty list");
     181
     182  LIST_NODE *node = list->first;
     183  list->first = node->next;
     184  //node->next = NULL;
     185  --(list->length);
     186  if(!list->first)
     187    list->last = list->first;
     188  return node;
     189}
     190
     191/**
     192 * @brief Remove and free first node from list
     193 *
     194 * @param list    Pointer to list
     195 */
     196void listRemoveFront(LIST *list)
     197{
     198  assertStreamPrint(NULL, 0 != list, "invalid list-pointer");
     199  if(list->first)
    156200  {
    157     if(list->first)
    158     {
    159       LIST_NODE *tmpNode = list->first->next;
    160       freeNode(list->first);
    161 
    162       list->first = tmpNode;
    163       --(list->length);
    164       if(!list->first)
    165         list->last = list->first;
    166     }
     201    LIST_NODE *tmpNode = list->first->next;
     202    freeNode(list->first);
     203
     204    list->first = tmpNode;
     205    --(list->length);
     206    if(!list->first)
     207      list->last = list->first;
    167208  }
    168209}
  • OMCompiler/SimulationRuntime/c/util/list.h

    rcaa3fcca r58677f97  
    6161
    6262  void listPushFront(LIST *list, const void *data);
     63  void listPushFrontNodeNoCopy(LIST *list, LIST_NODE *node);
    6364  void listPushBack(LIST *list, const void *data);
    6465  void listInsert(LIST *list, LIST_NODE* prevNode, const void *data);
     
    6970  void *listLastData(LIST *list);
    7071
    71   void listPopFront(LIST *list);
     72  LIST_NODE *listPopFrontNode(LIST *list);
     73  void listRemoveFront(LIST *list);
    7274
    7375  void listClear(LIST *list);
Note: See TracChangeset for help on using the changeset viewer.