# HG changeset patch # User Markus Mützel # Date 1627657556 -7200 # Node ID 2420f8f62ebe58ec644fbc4f23835d87faa87ce0 # Parent 6a8642d310c851792778a51120c162d2a7c07df5 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. diff -r 6a8642d310c8 -r 2420f8f62ebe libinterp/corefcn/dlmread.cc --- 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 #include #include #include @@ -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