removed some pointer dereference from critical path
[lttv.git] / ltt / branches / poly / ltt / facility.c
index 3cd638d57f81cdc6ae359f0e00c42e440f556ce5..55077aa3d1d713b529d8f561791bcfdd68e2827a 100644 (file)
@@ -1,9 +1,28 @@
+/* This file is part of the Linux Trace Toolkit viewer
+ * Copyright (C) 2003-2004 Xiangxiu Yang
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, 
+ * MA 02111-1307, USA.
+ */
+
 #include <stdlib.h> 
 #include <string.h>
 #include <stdio.h>
 
-#include <ltt/LTTTypes.h>  
 #include "parser.h"
+#include <ltt/ltt.h>
+#include "ltt-private.h"
 #include <ltt/facility.h>
 
 /* search for the (named) type in the table, if it does not exist
@@ -15,7 +34,7 @@ void constructTypeAndFields(LttFacility * fac,type_descriptor * td,
                             LttField * fld);
 
 /* generate the facility according to the events belongin to it */
-void generateFacility(LttFacility * f, facility  * fac, 
+void generateFacility(LttFacility * f, facility_t  * fac, 
                       LttChecksum checksum);
 
 /* functions to release the memory occupied by a facility */
@@ -39,7 +58,7 @@ void ltt_facility_open(LttTrace * t, char * pathname)
   char *token;
   parse_file in;
   char buffer[BUFFER_SIZE];
-  facility * fac;
+  facility_t * fac;
   LttFacility * f;
   LttChecksum checksum;
 
@@ -59,7 +78,7 @@ void ltt_facility_open(LttTrace * t, char * pathname)
     token = getName(&in);
     
     if(strcmp("facility",token) == 0) {
-      fac = g_new(facility, 1);
+      fac = g_new(facility_t, 1);
       fac->name = NULL;
       fac->description = NULL;
       sequence_init(&(fac->events));
@@ -69,9 +88,9 @@ void ltt_facility_open(LttTrace * t, char * pathname)
       parseFacility(&in, fac);
 
       //check if any namedType is not defined
-      checkNamedTypesImplemented(&fac->named_types);
+      g_assert(checkNamedTypesImplemented(&fac->named_types) == 0);
     
-      generateChecksum(fac->name, &checksum, &fac->events);
+      g_assert(generateChecksum(fac->name, &checksum, &fac->events) == 0);
 
       f = g_new(LttFacility,1);    
       f->base_id = 0;
@@ -105,7 +124,7 @@ void ltt_facility_open(LttTrace * t, char * pathname)
  *    checksum            : checksum of the facility          
  ****************************************************************************/
 
-void generateFacility(LttFacility *f, facility *fac,LttChecksum checksum)
+void generateFacility(LttFacility *f, facility_t *fac,LttChecksum checksum)
 {
   char * facilityName = fac->name;
   sequence * events = &fac->events;
@@ -129,17 +148,17 @@ void generateFacility(LttFacility *f, facility *fac,LttChecksum checksum)
     evType = g_new(LttEventType,1);
     f->events[i] = evType;
 
-    evType->name = g_strdup(((event*)(events->array[i]))->name);
-    evType->description=g_strdup(((event*)(events->array[i]))->description);
+    evType->name = g_strdup(((event_t*)(events->array[i]))->name);
+    evType->description=g_strdup(((event_t*)(events->array[i]))->description);
     
     field = g_new(LttField, 1);
     evType->root_field = field;
     evType->facility = f;
     evType->index = i;
 
-    if(((event*)(events->array[i]))->type != NULL){
+    if(((event_t*)(events->array[i]))->type != NULL){
       field->field_pos = 0;
-      type = lookup_named_type(f,((event*)(events->array[i]))->type);
+      type = lookup_named_type(f,((event_t*)(events->array[i]))->type);
       field->field_type = type;
       field->offset_root = 0;
       field->fixed_root = 1;
@@ -153,7 +172,7 @@ void generateFacility(LttFacility *f, facility *fac,LttChecksum checksum)
       field->current_element = 0;
 
       //construct field tree and type graph
-      constructTypeAndFields(f,((event*)(events->array[i]))->type,field);
+      constructTypeAndFields(f,((event_t*)(events->array[i]))->type,field);
     }else{
       evType->root_field = NULL;
       g_free(field);
@@ -223,7 +242,7 @@ void constructTypeAndFields(LttFacility * fac,type_descriptor * td,
 
     fld->child = g_new(LttField*, td->fields.position);      
     for(i=0;i<td->fields.position;i++){
-      tmpTd = ((field*)(td->fields.array[i]))->type;
+      tmpTd = ((type_fields*)(td->fields.array[i]))->type;
 
       if(flag)
        fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd);
@@ -234,7 +253,7 @@ void constructTypeAndFields(LttFacility * fac,type_descriptor * td,
 
       if(flag){
        fld->child[i]->field_type->element_name 
-         = g_strdup(((field*)(td->fields.array[i]))->name);
+         = g_strdup(((type_fields*)(td->fields.array[i]))->name);
       }
 
       fld->child[i]->offset_root = -1;
@@ -267,17 +286,18 @@ void constructTypeAndFields(LttFacility * fac,type_descriptor * td,
 LttType * lookup_named_type(LttFacility *fac, type_descriptor * td)
 {
   LttType * lttType = NULL;
-  int i;
+  unsigned int i=0;
   char * name;
+
   if(td->type_name){
     for(i=0;i<fac->named_types_number; i++){
       if(fac->named_types[i] == NULL) break;
       name = fac->named_types[i]->type_name;
       if(strcmp(name, td->type_name)==0){
-       lttType = fac->named_types[i];  
+             lttType = fac->named_types[i];    
        //      if(lttType->element_name) g_free(lttType->element_name);
        //      lttType->element_name = NULL;
-       break;  
+             break;    
       }
     }
   }
@@ -294,7 +314,7 @@ LttType * lookup_named_type(LttFacility *fac, type_descriptor * td)
     lttType->element_name = NULL;
     if(td->type_name){
       lttType->type_name = g_strdup(td->type_name);
-      fac->named_types[i] = lttType;
+      fac->named_types[i] = lttType; /* i is initialized, checked. */
     }
     else{
       lttType->type_name = NULL;
@@ -329,7 +349,7 @@ int ltt_facility_close(LttFacility *f)
 
 void freeFacility(LttFacility * fac)
 {
-  int i;
+  unsigned int i;
   g_free(fac->name);  //free facility name
 
   //free event types
@@ -366,7 +386,6 @@ void freeEventtype(LttEventType * evType)
 
 void freeLttNamedType(LttType * type)
 {
-  int i;
   g_free(type->type_name);
   type->type_name = NULL;
   freeLttType(&type);
@@ -374,7 +393,7 @@ void freeLttNamedType(LttType * type)
 
 void freeLttType(LttType ** type)
 {
-  int i;
+  unsigned int i;
   if(*type == NULL) return;
   if((*type)->type_name){
     return; //this is a named type
@@ -474,7 +493,7 @@ unsigned ltt_facility_base_id(LttFacility *f)
 
 unsigned ltt_facility_eventtype_number(LttFacility *f)
 {
-  return (unsigned)(f->event_number);
+  return (f->event_number);
 }
 
 /*****************************************************************************
@@ -498,7 +517,7 @@ LttEventType *ltt_facility_eventtype_get(LttFacility *f, unsigned i)
  *                     : obtain the event type according to event name
  *                       event name is unique in the facility
  *Input params
- *    f                : the facility that will be closed
+ *    f                : the facility
  *    name             : the name of the event
  *Return value
  *    LttEventType *  : the event type required  
@@ -506,14 +525,16 @@ LttEventType *ltt_facility_eventtype_get(LttFacility *f, unsigned i)
 
 LttEventType *ltt_facility_eventtype_get_by_name(LttFacility *f, char *name)
 {
-  int i;
-  LttEventType * ev;
+  unsigned int i;
+  LttEventType * ev = NULL;
+  
   for(i=0;i<f->event_number;i++){
-    ev = f->events[i];
-    if(strcmp(ev->name, name) == 0)break;      
+    LttEventType *iter_ev = f->events[i];
+    if(strcmp(iter_ev->name, name) == 0) {
+      ev = iter_ev;
+      break;
+    }
   }
-
-  if(i==f->event_number) return NULL;
-  else return ev;
+  return ev;
 }
 
This page took 0.026802 seconds and 4 git commands to generate.