Project

General

Profile

Feature #9667

Optimization of __FILE__ and __dir__

Added by sawa (Tsuyoshi Sawada) over 5 years ago. Updated over 5 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:61653]

Description

In the same spirit as the string literal followed by freeze is optimized, I think __FILE__ and __dir__ should be optimized. Currently, they return different object id each time they are called.

__FILE__.object_id # => 70183725179420
__FILE__.object_id # => 70183725129020
...

I propose them to be optimized so that they are only created once per occurrence.

__FILE__.object_id # => 70183725179420
__FILE__.object_id # => 70183725179420
...

History

Updated by sawa (Tsuyoshi Sawada) over 5 years ago

Sorry, my examples were inappropriate. Please ignore the examples above.

Currently, different object id is returned each time:

2.times{puts __FILE__.object_id}
# => 70183725179420
# => 70183725129020

I propose them to be optimized so that they are only created once per occurrence.

2.times{puts __FILE__.object_id}
# => 70183725179420
# => 70183725179420

Updated by nobu (Nobuyoshi Nakada) over 5 years ago

test/rubygems/test_gem.rb fails at untainting __FILE__, when parallel test.

Also available in: Atom PDF