More use of temp allocator.

This commit is contained in:
Christoffer Lerno
2023-07-19 02:46:43 +02:00
parent 5a2fe4c9d9
commit 5c2e82fc8b
7 changed files with 25 additions and 19 deletions

View File

@@ -68,9 +68,9 @@ fn String join(String[] s, String joiner, Allocator* using = mem::heap())
{
total_size += str.len;
}
@stack_mem(256; Allocator* mem)
@pool(using)
{
DString res = dstring::new_with_capacity(total_size, .using = mem);
DString res = dstring::tnew_with_capacity(total_size);
res.append(s[0]);
foreach (String* &str : s[1..])
{
@@ -416,6 +416,9 @@ fn String! from_wstring(WString wstring, Allocator* using = mem::heap())
return from_utf16(utf16, using);
}
fn String! temp_from_wstring(WString wstring) => from_wstring(wstring) @inline;
fn String! temp_from_utf16(Char16[] utf16) => temp_from_utf16(utf16) @inline;
fn usz String.utf8_codepoints(s)
{
usz len = 0;

View File

@@ -21,9 +21,9 @@ fn void CsvReader.init(&self, Stream stream, String separator = ",")
fn String[]! CsvReader.read_row(self, Allocator* using = mem::heap())
{
@stack_mem(512; Allocator* mem)
@pool()
{
return self.stream.readline(mem).split(self.separator, .using = using);
return self.stream.treadline().split(self.separator, .using = using);
};
}

View File

@@ -135,9 +135,9 @@ macro bool! Formatter.print_with_function(&self, any arg)
self.width = old_width;
self.prec = old_prec;
}
@stack_mem(512; Allocator* mem)
@pool()
{
self.out_substr(arg.to_string(mem))!;
self.out_substr(arg.to_string(mem::temp()))!;
return true;
};
}

View File

@@ -111,6 +111,8 @@ fn usz! Stream.read_all(self, char[] buffer) @inline
return n;
}
fn String! Stream.treadline(self) => self.readline(mem::temp()) @inline;
fn String! Stream.readline(self, Allocator* using = mem::heap())
{
ReadByteStreamFn func;
@@ -118,9 +120,9 @@ fn String! Stream.readline(self, Allocator* using = mem::heap())
bool read = false;
char val = func(self)!;
if (val == '\n') return "";
@stack_mem(256 + 64; Allocator* mem)
@pool(using)
{
DString str = dstring::new_with_capacity(256, .using = mem);
DString str = dstring::tnew_with_capacity(256);
if (val != '\r') str.append(val);
while (1)
{

View File

@@ -26,9 +26,10 @@ fn PathList! native_ls(Path dir, bool no_dirs, bool no_symlinks, String mask, Al
{
PathList list;
list.init(.using = using);
@stack_mem(1024; Allocator* mem)
@pool(using)
{
WString result = dir.as_str().concat(`\*`).to_wstring(.using = mem)!!;
WString result = dir.as_str().tconcat(`\*`).to_temp_wstring()!!;
Win32_WIN32_FIND_DATAW find_data;
Win32_HANDLE find = win32::findFirstFileW(result, &find_data);
if (find == win32::INVALID_HANDLE_VALUE) return IoError.CANNOT_READ_DIR?;
@@ -36,9 +37,9 @@ fn PathList! native_ls(Path dir, bool no_dirs, bool no_symlinks, String mask, Al
do
{
if (no_dirs && (find_data.dwFileAttributes & win32::FILE_ATTRIBUTE_DIRECTORY)) continue;
@stack_mem(480; Allocator* mem2)
@pool(using)
{
String filename = string::from_wstring((WString)&find_data.cFileName, mem2)!;
String filename = string::temp_from_wstring((WString)&find_data.cFileName)!;
if (filename == ".." || filename == ".") continue;
list.append(path::new(filename, using));
};

View File

@@ -12,13 +12,13 @@ fn Path! native_temp_directory(Allocator* using = mem::heap()) @if(!env::WIN32)
fn Path! native_temp_directory(Allocator* using = mem::heap()) @if(env::WIN32)
{
@stack_mem(256; Allocator* mem)
@pool(using)
{
Win32_DWORD len = win32::getTempPathW(0, null);
if (!len) return IoError.GENERAL_ERROR?;
Char16[] buff = malloc(Char16, len + 1, .using = mem);
Char16[] buff = tmalloc(Char16, len + 1);
if (!win32::getTempPathW(len, buff)) return IoError.GENERAL_ERROR?;
return path::new(string::from_utf16(buff[:len], .using = mem), using);
return path::new(string::temp_from_utf16(buff[:len]), using);
};
}

View File

@@ -29,9 +29,9 @@ enum PathEnv
fn Path! getcwd(Allocator* using = mem::heap())
{
@stack_mem(256; Allocator* mem)
@pool(using)
{
return new(os::getcwd(mem), using);
return new(os::getcwd(mem::temp()), using);
};
}
@@ -113,9 +113,9 @@ fn Path! new(String path, Allocator* using = mem::heap(), PathEnv path_env = DEF
fn Path! new_win32_wstring(WString path, Allocator* using = mem::heap())
{
@stack_mem(480; Allocator* mem)
@pool(using)
{
return path::new(string::from_wstring(path, .using = mem)!, .using = using);
return path::new(string::temp_from_wstring(path)!, .using = using);
};
}