[cairo-commit] rcairo/packages/cairo/ext rb_cairo_context.c, 1.33, 1.34

Kouhei Sutou commit at pdx.freedesktop.org
Mon Jan 1 07:33:24 PST 2007


Committed by: kou

Update of /cvs/cairo/rcairo/packages/cairo/ext
In directory kemper:/tmp/cvs-serv10810/packages/cairo/ext

Modified Files:
	rb_cairo_context.c 
Log Message:
* packages/cairo/ext/rb_cairo_context.c: cached Ruby object for source.


Index: rb_cairo_context.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_context.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- rb_cairo_context.c	29 Dec 2006 12:37:25 -0000	1.33
+++ rb_cairo_context.c	1 Jan 2007 15:33:20 -0000	1.34
@@ -17,7 +17,7 @@
 
 VALUE rb_cCairo_Context;
 
-static ID cr_id_source, cr_id_source_class;
+static ID cr_id_surface, cr_id_source, cr_id_source_class;
 
 #define _SELF  (RVAL2CRCONTEXT(self))
 
@@ -93,7 +93,7 @@
 
   cr = cairo_create (RVAL2CRSURFACE (target));
   cr_check_status (cr);
-  rb_ivar_set (self, cr_id_source, target);
+  rb_ivar_set (self, cr_id_surface, target);
   DATA_PTR(self) = cr;
   return Qnil;
 }
@@ -216,6 +216,7 @@
                 StringValuePtr (inspected_arg));
     }
   cr_check_status (_SELF);
+  rb_ivar_set (self, cr_id_source, Qnil);
   rb_ivar_set (self, cr_id_source_class, rb_cCairo_SolidPattern);
   return self;
 }
@@ -264,6 +265,7 @@
                 StringValuePtr (inspected_arg));
     }
   cr_check_status (_SELF);
+  rb_ivar_set (self, cr_id_source, Qnil);
   rb_ivar_set (self, cr_id_source_class, rb_cCairo_SolidPattern);
   return self;
 }
@@ -276,6 +278,7 @@
                             NUM2INT (width),
                             NUM2INT (height));
   cr_check_status (_SELF);
+  rb_ivar_set (self, cr_id_source, Qnil);
   rb_ivar_set (self, cr_id_source_class, rb_cCairo_SurfacePattern);
   return self;
 }
@@ -285,6 +288,7 @@
 {
   cairo_set_source (_SELF, RVAL2CRPATTERN (pattern));
   cr_check_status (_SELF);
+  rb_ivar_set (self, cr_id_source, pattern);
   rb_ivar_set (self, cr_id_source_class, rb_obj_class (pattern));
   return self;
 }
@@ -1063,16 +1067,28 @@
 static VALUE
 cr_get_source (VALUE self)
 {
+  VALUE rb_source = Qnil;
   cairo_pattern_t *source;
   source = cairo_get_source (_SELF);
 
+  rb_source = rb_ivar_get (self, cr_id_source);
   if (source)
     {
       rb_cairo_check_status (cairo_pattern_status (source));
-      return CRPATTERN2RVAL (source, rb_ivar_get (self, cr_id_source_class));
+      if (NIL_P (rb_source) || RVAL2CRPATTERN (rb_source) != source)
+        {
+          rb_source =
+            CRPATTERN2RVAL (source, rb_ivar_get (self, cr_id_source_class));
+          rb_ivar_set (self, cr_id_source, rb_source);
+        }
     }
   else
-    return Qnil;
+    {
+      rb_source = Qnil;
+      rb_ivar_set (self, cr_id_source, rb_source);
+    }
+
+  return rb_source;
 }
 
 static VALUE
@@ -1171,11 +1187,11 @@
   surface = cairo_get_target (_SELF);
   rb_cairo_check_status (cairo_surface_status (surface));
 
-  rb_surface = rb_ivar_get (self, cr_id_source);
+  rb_surface = rb_ivar_get (self, cr_id_surface);
   if (NIL_P (rb_surface) || RVAL2CRSURFACE (rb_surface) != surface)
     {
       rb_surface = CRSURFACE2RVAL (surface);
-      rb_ivar_set (self, cr_id_source, rb_surface);
+      rb_ivar_set (self, cr_id_surface, rb_surface);
     }
 
   return rb_surface;
@@ -1219,6 +1235,7 @@
 void
 Init_cairo_context (void)
 {
+  cr_id_surface = rb_intern ("surface");
   cr_id_source = rb_intern ("source");
   cr_id_source_class = rb_intern ("source_class");
 



More information about the cairo-commit mailing list