Created
October 9, 2013 22:42
-
-
Save tmm1/6909796 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/vm_core.h b/vm_core.h | |
index 4c6e3c2..c65dcc1 100644 | |
--- a/vm_core.h | |
+++ b/vm_core.h | |
@@ -389,7 +389,7 @@ typedef struct rb_vm_struct { | |
/* hook */ | |
rb_hook_list_t event_hooks; | |
- struct rb_postponed_job_struct *postponed_job; | |
+ struct rb_postponed_job_struct *postponed_job, *postponed_job_freelist; | |
int src_encoding_index; | |
diff --git a/vm_trace.c b/vm_trace.c | |
index d01ff8c..3c32218 100644 | |
--- a/vm_trace.c | |
+++ b/vm_trace.c | |
@@ -1385,7 +1385,14 @@ rb_postponed_job_register(unsigned int flags, rb_postponed_job_func_t func, void | |
{ | |
rb_thread_t *th = GET_THREAD(); | |
rb_vm_t *vm = th->vm; | |
- rb_postponed_job_t *pjob = (rb_postponed_job_t *)ruby_xmalloc(sizeof(rb_postponed_job_t)); | |
+ rb_postponed_job_t *pjob; | |
+ | |
+ if (vm->postponed_job_freelist) { | |
+ pjob = vm->postponed_job_freelist; | |
+ vm->postponed_job_freelist = pjob->next; | |
+ } else { | |
+ pjob = (rb_postponed_job_t *)ruby_xmalloc(sizeof(rb_postponed_job_t)); | |
+ } | |
if (pjob == NULL) return 0; /* failed */ | |
pjob->flags = flags; | |
@@ -1425,7 +1432,10 @@ rb_postponed_job_flush(rb_vm_t *vm) | |
while (pjob) { | |
next_pjob = pjob->next; | |
pjob->func(pjob->data); | |
- ruby_xfree(pjob); | |
+ | |
+ pjob->next = vm->postponed_job_freelist; | |
+ vm->postponed_job_freelist = pjob; | |
+ | |
pjob = next_pjob; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment