Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor code, add defensive checks for every string pointer being no…

…t null
  • Loading branch information...
commit 328035a30829a89f9071aa6419f23bf219fb46d0 1 parent 7a3314f
Stephen Sykes authored
Showing with 8 additions and 18 deletions.
  1. +8 −18 ext/callsite_hash.c
26 ext/callsite_hash.c
View
@@ -6,7 +6,6 @@
static int strhash(register const char *string) {
register int c;
-
register int val = 0;
while ((c = *string++) != '\0') {
@@ -16,35 +15,26 @@ static int strhash(register const char *string) {
return val + (val>>5);
}
-static VALUE rb_f_callsite( VALUE obj ) {
+static VALUE rb_f_callsite(VALUE obj) {
struct FRAME *frame = ruby_frame;
NODE *n;
int csite = 0;
- if (frame->last_func == ID_ALLOCATOR) {
- frame = frame->prev;
- }
+ if (frame->last_func == ID_ALLOCATOR) frame = frame->prev;
+
ruby_set_current_source();
- if (frame->last_func) {
- csite += strhash(ruby_sourcefile) + ruby_sourceline + frame->last_func;
- }
- else if (ruby_sourceline == 0) {
- csite += strhash(ruby_sourcefile);
- }
- else {
- csite += strhash(ruby_sourcefile) + ruby_sourceline;
- }
+ if (ruby_sourcefile) csite += strhash(ruby_sourcefile);
+ csite += frame->last_func + ruby_sourceline;
for (; frame && (n = frame->node); frame = frame->prev) {
if (frame->prev && frame->prev->last_func) {
if (frame->prev->node == n) {
if (frame->prev->last_func == frame->last_func) continue;
}
- csite += strhash(n->nd_file) + nd_line(n) + frame->prev->last_func;
- }
- else {
- csite += strhash(n->nd_file) + nd_line(n);
+ csite += frame->prev->last_func;
}
+ if (n->nd_file) csite += strhash(n->nd_file);
+ csite += nd_line(n);
}
return INT2FIX(csite);
Please sign in to comment.
Something went wrong with that request. Please try again.