Change Process.identifier to return an Integer

Ever since Integer.format has been introduced there no longer is a
reason to have the VM format the identifier as a string. Using an
integer also saves a heap allocation for cases where we don't need/want
a string.
parent d3841771
Pipeline #104097189 passed with stages
in 15 minutes and 25 seconds
......@@ -1652,7 +1652,7 @@ module Inkoc
end
def on_raw_process_identifier(*)
typedb.string_type.new_instance
typedb.integer_type.new_instance
end
def on_raw_library_open(node, _)
......
......@@ -81,11 +81,8 @@ object Process {
# Returns the identifier associated with this process.
#
# The identifier is unique for every process, but might be different between
# program invocations even for processes spawned in the same order. The
# format of the identifier is also unspecified, and might change
# unexpectedly. Process identifiers should only be used for debugging
# purposes.
def identifier -> String {
# program invocations even for processes spawned in the same order.
def identifier -> Integer {
_INKOC.process_identifier(self)
}
}
......
......@@ -78,8 +78,8 @@ panicking lambda (error) {
}
}
output.push("\nProcess ")
output.push(process.current.identifier)
output.push("\nProcess 0x")
output.push(process.current.identifier.format(radix: 16))
output.push(' panicked: ')
output.push(error)
......
......@@ -26,7 +26,7 @@ def temporary_file_path -> Path {
env.temporary_directory.to_string,
SEPARATOR,
'inko-temporary-file-path-',
process.current.identifier,
process.current.identifier.to_string,
)
.to_string
......
......@@ -13,7 +13,7 @@ let TEMP = env.temporary_directory.to_string
def temp_dir(components = Array.new!(String)) -> String {
let buffer = StringBuffer
.new(TEMP, SEPARATOR, 'inko-test-' + process.current.identifier)
.new(TEMP, SEPARATOR, 'inko-test-' + process.current.identifier.to_string)
components.each do (component) {
buffer.push(SEPARATOR)
......
......@@ -491,7 +491,7 @@ test.group('std::fs::file.remove') do (g) {
test.group('std::fs::file.copy') do (g) {
g.test('Copying an existing file') {
write_only_file do (f) {
let new_path = f.path.to_string + process.current.identifier
let new_path = f.path.to_string + process.current.identifier.to_string
process.defer {
try file.remove(new_path) else Nil
......
......@@ -4,7 +4,7 @@ import std::process
import std::test::assert
def temporary_environment_variable!(R)(block: do (String) -> R) -> R {
let name = 'INKO_ENV_' + process.current.identifier
let name = 'INKO_ENV_' + process.current.identifier.to_string
process.defer {
env.remove(name)
......
......@@ -20,6 +20,12 @@ test.group('std::process::Process.send') do (g) {
}
}
test.group('std::process::Process.identifier') do (g) {
g.test('Obtaining the identifier of a process') {
assert.true(process.current.identifier.positive?)
}
}
test.group('std::process.receive') do (g) {
g.test('Receiving a message without a timeout') {
process.current.send('testing')
......
......@@ -238,9 +238,9 @@ pub fn identifier(
) -> Result<ObjectPointer, String> {
let proc = process_ptr.process_value()?;
let proto = state.string_prototype;
let identifier = format!("{:#x}", proc.identifier());
let identifier = current_process.allocate_usize(proc.identifier(), proto);
Ok(current_process.allocate(object_value::string(identifier), proto))
Ok(identifier)
}
pub fn unwind_until_defining_scope(process: &RcProcess) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment