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

ruby-changes:73786

From: Nobuyoshi <ko1@a...>
Date: Thu, 29 Sep 2022 14:56:51 +0900 (JST)
Subject: [ruby-changes:73786] cb16dcb184 (master): [ruby/date] The shrunk words to be copied is limited

https://git.ruby-lang.org/ruby.git/commit/?id=cb16dcb184

From cb16dcb1849b3b971b34ef2405949a57e65b8a8a Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 29 Sep 2022 14:15:55 +0900
Subject: [ruby/date] The shrunk words to be copied is limited

Th buffer size is small enough and no need to allocate dynamically.

https://github.com/ruby/date/commit/f62bf0a01d
---
 ext/date/date_parse.c        | 5 ++---
 test/date/test_date_parse.rb | 1 +
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/ext/date/date_parse.c b/ext/date/date_parse.c
index 6155293bb9..7349c75d84 100644
--- a/ext/date/date_parse.c
+++ b/ext/date/date_parse.c
@@ -442,14 +442,14 @@ date_zone_to_diff(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L442
 	{
 	    const char *zn = s;
 	    long sl = shrunk_size(s, l);
-	    VALUE vbuf = 0;
+	    char shrunk_buff[MAX_WORD_LENGTH]; /* no terminator to be added */
 	    const struct zone *z = 0;
 
 	    if (sl <= 0) {
 		sl = l;
 	    }
 	    else if (sl <= MAX_WORD_LENGTH) {
-		char *d = ALLOCV_N(char, vbuf, sl);
+		char *d = shrunk_buff;
 		sl = shrink_space(d, s, l);
 		zn = d;
 	    }
@@ -457,7 +457,6 @@ date_zone_to_diff(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L457
 	    if (sl > 0 && sl <= MAX_WORD_LENGTH) {
 		z = zonetab(zn, (unsigned int)sl);
 	    }
-	    ALLOCV_END(vbuf);
 
 	    if (z) {
 		int d = z->offset;
diff --git a/test/date/test_date_parse.rb b/test/date/test_date_parse.rb
index 0b7fc269d0..0b4a383630 100644
--- a/test/date/test_date_parse.rb
+++ b/test/date/test_date_parse.rb
@@ -41,6 +41,7 @@ class TestDateParse < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/date/test_date_parse.rb#L41
      [['Sat Aug 28 02:29:34 Mountain Daylight Time 2000',false],[2000,8,28,2,29,34,'Mountain Daylight Time',-6*3600,6], __LINE__],
      [['Sat Aug 28 02:29:34 Mexico Standard Time 2000',false],[2000,8,28,2,29,34,'Mexico Standard Time',-6*3600,6], __LINE__],
      [['Sat Aug 28 02:29:34 E. Australia Standard Time 2000',false],[2000,8,28,2,29,34,'E. Australia Standard Time',10*3600,6], __LINE__],
+     [['Sat Aug 28 02:29:34 W.  Central  Africa  Standard  Time 2000',false],[2000,8,28,2,29,34,'W. Central Africa Standard Time',1*3600,6], __LINE__],
 
      # part of iso 8601
      [['1999-05-23 23:55:21',false],[1999,5,23,23,55,21,nil,nil,nil], __LINE__],
-- 
cgit v1.2.1


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

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