freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2-demos] master b0bcc5b: [graph] Stay true to linked lists.


From: Alexei Podtelezhnikov
Subject: [freetype2-demos] master b0bcc5b: [graph] Stay true to linked lists.
Date: Wed, 5 Jun 2019 23:59:42 -0400 (EDT)

branch: master
commit b0bcc5b096d863b68c86597c46f495fa97ee4ad9
Author: Alexei Podtelezhnikov <address@hidden>
Commit: Alexei Podtelezhnikov <address@hidden>

    [graph] Stay true to linked lists.
    
    * graph/grinit.c (grInitDevices, grDoneDevices): Properly walk and
    delete entries from the linked list `gr_device_chain'.
    * graph/grdevice.c (find_device): Ditto.
    * graph/grdevice.h (gr_num_devices, gr_max_devices): Removed.
    * graph/grconfig.h (GR_MAX_DEVICES): Ditto.
---
 ChangeLog        | 12 +++++++++++-
 graph/grconfig.h |  2 --
 graph/grdevice.c | 28 ++++++++++++++++------------
 graph/grdevice.h |  5 +----
 graph/grinit.c   | 41 ++++++++++-------------------------------
 5 files changed, 38 insertions(+), 50 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2bd5741..f30fa4f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2019-06-05  Alexei Podtelezhnikov  <address@hidden>
+
+       [graph] Stay true to linked lists.
+
+       * graph/grinit.c (grInitDevices, grDoneDevices): Properly walk and
+       delete entries from the linked list `gr_device_chain'.
+       * graph/grdevice.c (find_device): Ditto.
+       * graph/grdevice.h (gr_num_devices, gr_max_devices): Removed.
+       * graph/grconfig.h (GR_MAX_DEVICES): Ditto.
+
 2019-06-03  Alexei Podtelezhnikov  <address@hidden>
 
        [ftgrid,ftview,ftstring] Implement PNG printing.
@@ -237,7 +247,7 @@
        * src/ftcommon.h (FTDemo_String_Context): New fields for offset glyph
        and extent to fill.
        (FTDemo_String_Draw): Return the number of glyphs drawn.
-       * src/ftcommon.c (FTDemo_String_Draw): Implement glyph recycling until 
+       * src/ftcommon.c (FTDemo_String_Draw): Implement glyph recycling until
        the extent is full.
 
 2018-09-12  Alexei Podtelezhnikov  <address@hidden>
diff --git a/graph/grconfig.h b/graph/grconfig.h
index 8db2448..1ba102f 100644
--- a/graph/grconfig.h
+++ b/graph/grconfig.h
@@ -4,6 +4,4 @@
 #define GR_MAX_SATURATIONS  8
 #define GR_MAX_CONVERSIONS  16
 
-#define GR_MAX_DEVICES  8
-
 #endif /* GRCONFIG_H_ */
diff --git a/graph/grdevice.c b/graph/grdevice.c
index ebd9dc6..27413ee 100644
--- a/graph/grdevice.c
+++ b/graph/grdevice.c
@@ -3,28 +3,32 @@
 #include <stdlib.h>
 #include <string.h>
 
-  grDeviceChain   gr_device_chain[ GR_MAX_DEVICES ];
-  int             gr_num_devices = 0;
+  grDeviceChain*  gr_device_chain;
 
   static
   grDevice*  find_device( const char*  device_name )
   {
-    int  idx = 0;
+    grDeviceChain*  chain = gr_device_chain;
+    grDevice*       device = NULL;
 
     if (device_name)
-    {
-      for ( idx = gr_num_devices-1; idx > 0; idx-- )
-        if ( strcmp( device_name, gr_device_chain[idx].name ) == 0 )
+      while (chain)
+      {
+        if ( strcmp( device_name, chain->name ) == 0 )
+        {
+          device = chain->device;
           break;
-    }
+        }
 
-    if ( idx < 0 || gr_num_devices <= 0 || !gr_device_chain[idx].device )
-    {
+        chain = chain->next;
+      }
+    else if (chain)
+      device = chain->device;
+
+    if (!device)
       grError = gr_err_invalid_device;
-      return 0;
-    }
 
-    return gr_device_chain[idx].device;
+    return device;
   }
 
 
diff --git a/graph/grdevice.h b/graph/grdevice.h
index d74d53d..8fcb23c 100644
--- a/graph/grdevice.h
+++ b/graph/grdevice.h
@@ -120,10 +120,7 @@
   };
 
 
-  extern grDevice*      gr_devices[];
-  extern grDeviceChain  gr_device_chain[];
-  extern int            gr_num_devices;
-  extern int            gr_max_devices;
+  extern grDeviceChain*  gr_device_chain;
 
 
 extern void
diff --git a/graph/grinit.c b/graph/grinit.c
index f2fb47e..6fb9c38 100644
--- a/graph/grinit.c
+++ b/graph/grinit.c
@@ -63,55 +63,34 @@
   extern
   grDeviceChain*  grInitDevices( void )
   {
-    grDeviceChain*  chain = GR_INIT_DEVICE_CHAIN;
-    grDeviceChain*  cur   = gr_device_chain;
+    grDeviceChain*   chain;
+    grDeviceChain**  chptr;
 
+    chain = gr_device_chain = GR_INIT_DEVICE_CHAIN;
+    chptr = &gr_device_chain;
 
     while (chain)
     {
-      /* initialize the device */
-      grDevice*  device;
+      if ( chain->device->init() != 0 )
+        *chptr = chain->next;
 
-      device = chain->device;
-      if ( device->init() == 0             &&
-           gr_num_devices < GR_MAX_DEVICES )
-
-      {
-        /* successful device initialisation - add it to our chain */
-        cur->next   = 0;
-        cur->device = device;
-        cur->name   = device->device_name;
-
-        if (cur > gr_device_chain)
-          cur[-1].next = cur;
-
-        cur++;
-        gr_num_devices++;
-      }
+      chptr = &chain->next;
       chain = chain->next;
     }
 
-    return (gr_num_devices > 0 ? gr_device_chain : 0 );
+    return gr_device_chain;
   }
 
 
   extern
   void  grDoneDevices( void )
   {
-    int             i;
     grDeviceChain*  chain = gr_device_chain;
 
-
-    for ( i = 0; i < gr_num_devices; i++ )
+    while (chain)
     {
       chain->device->done();
 
-      chain->next   = 0;
-      chain->device = 0;
-      chain->name   = 0;
-
-      chain++;
+      chain = chain->next;
     }
-
-    gr_num_devices = 0;
   }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]