Mercurial > octave
changeset 29928:2420f8f62ebe
dlmread: Improve performance on platforms with slow setlocale (bug #59702).
* libinterp/corefcn/dlmread.cc (Fdlmread): Set locale to "C" for the duration of
reading floating point values from the input stream.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Fri, 30 Jul 2021 17:05:56 +0200 |
parents | 6a8642d310c8 |
children | aa98b5fdfbbb |
files | libinterp/corefcn/dlmread.cc |
diffstat | 1 files changed, 10 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/dlmread.cc Thu Jul 29 20:43:13 2021 -0400 +++ b/libinterp/corefcn/dlmread.cc Fri Jul 30 17:05:56 2021 +0200 @@ -30,6 +30,7 @@ # include "config.h" #endif +#include <clocale> #include <cmath> #include <cctype> #include <fstream> @@ -331,6 +332,15 @@ } } + // Set "C" locale for the remainder of this function to avoid the performance + // panelty of frequently switching the locale when reading floating point + // values from the stream. + char *prev_locale = std::setlocale (LC_ALL, nullptr); + std::string old_locale (prev_locale ? prev_locale : ""); + std::setlocale (LC_ALL, "C"); + octave::unwind_action act + ([old_locale] () { std::setlocale (LC_ALL, old_locale.c_str ()); }); + std::string line; // Skip the r0 leading lines