]> git.imager.perl.org - imager.git/commitdiff
re-work malloc_temp(), calloc_temp() to avoid SV overhead
authorTony Cook <tony@develop-help.com>
Sun, 21 Feb 2016 01:17:05 +0000 (12:17 +1100)
committerTony Cook <tony@develop-help.com>
Sun, 21 Feb 2016 01:17:05 +0000 (12:17 +1100)
Previosly they created a temp SV and returned it's buffer.  Now they
just call Newx() or Newxz() and SAVEFREEPV() the result.

Imager.xs

index ccfcf0df52ce3e705ee242c2e196635ebc714828..e16b42dd915276b4eca50b556dd1310a03ed8ed4 100644 (file)
--- a/Imager.xs
+++ b/Imager.xs
@@ -124,15 +124,18 @@ Allocate memory that will be discarded when mortals are discarded.
 
 static void *
 malloc_temp(pTHX_ size_t size) {
-  SV *sv = sv_2mortal(newSV(size));
+  void *result;
+  Newx(result, size, char);
+  SAVEFREEPV(result);
 
-  return SvPVX(sv);
+  return result;
 }
 
 static void *
 calloc_temp(pTHX_ size_t size) {
-  void *result = malloc_temp(aTHX_ size);
-  memset(result, 0, size);
+  void *result;
+  Newxz(result, size, char);
+  SAVEFREEPV(result);
 
   return result;
 }