Giter VIP home page Giter VIP logo

Comments (6)

tlvenn avatar tlvenn commented on May 18, 2024 1

Yes could leverage iodata and to some extend maybe a bit of https://github.com/benoitc/hackney/blob/master/doc/hackney_url.md

from stripity-stripe.

fastjames avatar fastjames commented on May 18, 2024 1

If your goal is to remove the ++ operation (which I understand for performance reasons) wouldn't the simple fix be something like this?

diff --git a/lib/stripe/uri.ex b/lib/stripe/uri.ex
index 7aa1bd9..5cfc55a 100644
--- a/lib/stripe/uri.ex
+++ b/lib/stripe/uri.ex
@@ -48,9 +48,9 @@ defmodule Stripe.URI do
     Enum.map_join values, "&", fn {key, value} ->
       cond do
         Enumerable.impl_for(value) ->
-          pair(root, parents ++ [key], value)
+          pair(root, [key | parents], value)
         true ->
-          build_key(root, parents ++ [key]) <> URI.encode_www_form(to_string(value))
+          build_key(root, Enum.reverse([key | parents])) <> URI.encode_www_form(to_string(value))
       end
     end
   end

or do you want to avoid Enum.reverse as well? I haven't read the source on that one but I assumed one round of it was OK.

from stripity-stripe.

fastjames avatar fastjames commented on May 18, 2024 1

Pull request submitted: #184

from stripity-stripe.

DavidAntaramian avatar DavidAntaramian commented on May 18, 2024

Yeah. I have an implementation using iodata in another system. I may just copy it over.

from stripity-stripe.

DavidAntaramian avatar DavidAntaramian commented on May 18, 2024

The Enum.reverse is fine. The problem with ++ is the way the memory allocation and copy-on-write mechanism works with the VM.

The solution that you have given looks like an improvement, but I think the overall logic (such as use of Enumerable.impl_for/1) can be improved.

from stripity-stripe.

joshsmith avatar joshsmith commented on May 18, 2024

@fastjames given that I think if you want to open a PR to spike this out and see if @DavidAntaramian or someone else can provide feedback on that, I'd be really thankful!

from stripity-stripe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.