{"action":"opened","issue":{"url":"https://api.github.com/repos/jhy/jsoup/issues/836","repository_url":"https://api.github.com/repos/jhy/jsoup","labels_url":"https://api.github.com/repos/jhy/jsoup/issues/836/labels{/name}","comments_url":"https://api.github.com/repos/jhy/jsoup/issues/836/comments","events_url":"https://api.github.com/repos/jhy/jsoup/issues/836/events","html_url":"https://github.com/jhy/jsoup/issues/836","id":209525706,"number":836,"title":"addChildren is cubic","user":{"login":"jart","id":49262,"avatar_url":"https://avatars.githubusercontent.com/u/49262?v=3","gravatar_id":"","url":"https://api.github.com/users/jart","html_url":"https://github.com/jart","followers_url":"https://api.github.com/users/jart/followers","following_url":"https://api.github.com/users/jart/following{/other_user}","gists_url":"https://api.github.com/users/jart/gists{/gist_id}","starred_url":"https://api.github.com/users/jart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jart/subscriptions","organizations_url":"https://api.github.com/users/jart/orgs","repos_url":"https://api.github.com/users/jart/repos","events_url":"https://api.github.com/users/jart/events{/privacy}","received_events_url":"https://api.github.com/users/jart/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-02-22T17:31:48Z","updated_at":"2017-02-22T17:31:48Z","closed_at":null,"body":"A performance improvement was made for `Node#addChildren` a few years ago in #504. But the performance gain only applies when appending nodes without a parent. Worst case is still O(n^3).\r\n\r\nCould we make it more like this?\r\n\r\n```java\r\npublic void addChildren(int index, List<? extends Node> children) {\r\n  for (Node child : children) {\r\n    if (child == null) {\r\n      throw new NullPointerException();\r\n    }\r\n    if (equals(child.parentNode)) {\r\n      throw new IllegalArgumentException();\r\n    }\r\n  }\r\n  ensureChildNodes();\r\n  int oldChildCount = childNodes.size();\r\n  int start = Math.min(0, oldChildCount - children.size());\r\n  for (int i = start; i < oldChildCount; i++) {\r\n    Node child = childNodes.get(i);\r\n    childNodes.add(child);\r\n    child.siblingIndex += children.size();\r\n  }\r\n  for (int i = children.size() - 1; i >= 0; i--) {\r\n    Node in = children.get(i);\r\n    reparentChild(in);\r\n    childNodes.set(start + i, in);\r\n  }\r\n}\r\n```\r\n\r\nThat would be much faster."}}
{"actor":{"display_login":"jart"}}