[前][次][番号順一覧][スレッド一覧]

ruby-changes:50002

From: nobu <ko1@a...>
Date: Wed, 31 Jan 2018 13:02:25 +0900 (JST)
Subject: [ruby-changes:50002] nobu:r62120 (trunk): io.c: simplified pipe_del_fptr

nobu	2018-01-31 13:02:18 +0900 (Wed, 31 Jan 2018)

  New Revision: 62120

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62120

  Log:
    io.c: simplified pipe_del_fptr
    
    * io.c (pipe_del_fptr): merged code for the case fptr is first to
      the loop for the rest.

  Modified files:
    trunk/io.c
Index: io.c
===================================================================
--- io.c	(revision 62119)
+++ io.c	(revision 62120)
@@ -6150,23 +6150,16 @@ pipe_add_fptr(rb_io_t *fptr) https://github.com/ruby/ruby/blob/trunk/io.c#L6150
 static void
 pipe_del_fptr(rb_io_t *fptr)
 {
-    struct pipe_list *list = pipe_list;
+    struct pipe_list **prev = &pipe_list;
     struct pipe_list *tmp;
 
-    if (list->fptr == fptr) {
-	pipe_list = list->next;
-	free(list);
-	return;
-    }
-
-    while (list->next) {
-	if (list->next->fptr == fptr) {
-	    tmp = list->next;
-	    list->next = list->next->next;
+    while ((tmp = *prev) != 0) {
+	if (tmp->fptr == fptr) {
+	    *prev = tmp->next;
 	    free(tmp);
 	    return;
 	}
-	list = list->next;
+	prev = &tmp->next;
     }
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]