From 85a6ce4c8f093540e0d86ba05a4a773ccdc78c25 Mon Sep 17 00:00:00 2001 From: Aaron Tinio Date: Wed, 21 Nov 2018 18:49:11 +0800 Subject: [PATCH] Fixed: Performance regression on Faker.Util.pick/1 (#221) Removed `Enum.to_list/1` call since `Enum.at/2` works fine with any enum. Fixes #213 and fixes #219. --- CHANGELOG.md | 2 ++ lib/faker/util.ex | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a56f4f05c..4478277b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ Change log itself follows [Keep a CHANGELOG](http://keepachangelog.com) format. ### Fixed +* `Faker.Util.pick/1` performance regression [[@aptinio][]] + ### Security ## 0.11.1 diff --git a/lib/faker/util.ex b/lib/faker/util.ex index 9edcb42cb..9945083a5 100644 --- a/lib/faker/util.ex +++ b/lib/faker/util.ex @@ -27,9 +27,7 @@ defmodule Faker.Util do end def pick(enum) do - enum - |> Enum.to_list() - |> Enum.at(Faker.random_between(0, Enum.count(enum) - 1)) + Enum.at(enum, Faker.random_between(0, Enum.count(enum) - 1)) end @doc """